-
Notifications
You must be signed in to change notification settings - Fork 966
Convert Android LLM extension from Java to Kotlin (#19211) #19211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kirklandsign
wants to merge
1
commit into
main
Choose a base branch
from
export-D102880053
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 0 additions & 198 deletions
198
...torch_android/src/main/java/org/pytorch/executorch/extension/llm/LlmGenerationConfig.java
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
...cutorch_android/src/main/java/org/pytorch/executorch/extension/llm/LlmGenerationConfig.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| package org.pytorch.executorch.extension.llm | ||
|
|
||
| /** | ||
| * Configuration class for controlling text generation parameters in LLM operations. | ||
| * | ||
| * This class provides settings for text generation behavior including output formatting, generation | ||
| * limits, and sampling parameters. Instances should be created using the [create] method and the | ||
| * fluent builder pattern. | ||
| */ | ||
| class LlmGenerationConfig | ||
| private constructor( | ||
| @get:JvmName("isEcho") val echo: Boolean, | ||
| val maxNewTokens: Int, | ||
| @get:JvmName("isWarming") val warming: Boolean, | ||
| val seqLen: Int, | ||
| val temperature: Float, | ||
| val numBos: Int, | ||
| val numEos: Int, | ||
| ) { | ||
|
|
||
| companion object { | ||
| /** | ||
| * Creates a new Builder instance for constructing generation configurations. | ||
| * | ||
| * @return a new Builder with default configuration values | ||
| */ | ||
| @JvmStatic fun create(): Builder = Builder() | ||
| } | ||
|
|
||
| /** | ||
| * Builder class for constructing LlmGenerationConfig instances. | ||
| * | ||
| * Provides a fluent interface for configuring generation parameters with sensible defaults. All | ||
| * methods return the builder instance to enable method chaining. | ||
| */ | ||
| class Builder internal constructor() { | ||
| private var echo: Boolean = true | ||
| private var maxNewTokens: Int = -1 | ||
| private var warming: Boolean = false | ||
| private var seqLen: Int = -1 | ||
| private var temperature: Float = 0.8f | ||
| private var numBos: Int = 0 | ||
| private var numEos: Int = 0 | ||
|
|
||
| /** Sets whether to include the input prompt in the generated output. */ | ||
| fun echo(echo: Boolean): Builder = apply { this.echo = echo } | ||
|
|
||
| /** Sets the maximum number of new tokens to generate. */ | ||
| fun maxNewTokens(maxNewTokens: Int): Builder = apply { this.maxNewTokens = maxNewTokens } | ||
|
|
||
| /** Enables or disables model warming. */ | ||
| fun warming(warming: Boolean): Builder = apply { this.warming = warming } | ||
|
|
||
| /** Sets the maximum sequence length for generation. */ | ||
| fun seqLen(seqLen: Int): Builder = apply { this.seqLen = seqLen } | ||
|
|
||
| /** Sets the temperature for random sampling. */ | ||
| fun temperature(temperature: Float): Builder = apply { this.temperature = temperature } | ||
|
|
||
| /** Sets the number of BOS tokens to prepend. */ | ||
| fun numBos(numBos: Int): Builder = apply { this.numBos = numBos } | ||
|
|
||
| /** Sets the number of EOS tokens to append. */ | ||
| fun numEos(numEos: Int): Builder = apply { this.numEos = numEos } | ||
|
|
||
| /** Constructs the LlmGenerationConfig instance with the configured parameters. */ | ||
| fun build(): LlmGenerationConfig = | ||
| LlmGenerationConfig(echo, maxNewTokens, warming, seqLen, temperature, numBos, numEos) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description says
package-info.javawas removed, butorg/pytorch/executorch/extension/llm/package-info.javastill exists in this package. Either remove it as described, or update the PR description to avoid confusion about what changed.