Skip to content

Make seq_len param available in JNI layer generate() #4745

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

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion extension/android/jni/jni_layer_llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ class ExecuTorchLlamaJni

jint generate(
facebook::jni::alias_ref<jstring> prompt,
jint seq_len,
facebook::jni::alias_ref<ExecuTorchLlamaCallbackJni> callback) {
runner_->generate(
prompt->toStdString(),
128,
seq_len,
[callback](std::string result) { callback->onResult(result); },
[callback](const Stats& result) { callback->onStats(result); });
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class LlamaModule {
}

private final HybridData mHybridData;
private static final int DEFAULT_SEQ_LEN = 128;

@DoNotStrip
private static native HybridData initHybrid(
Expand All @@ -42,8 +43,19 @@ public void resetNative() {
* @param prompt Input prompt
* @param llamaCallback callback object to receive results.
*/
public int generate(String prompt, LlamaCallback llamaCallback) {
return generate(prompt, DEFAULT_SEQ_LEN, llamaCallback);
}

/**
* Start generating tokens from the module.
*
* @param prompt Input prompt
* @param seqLen sequence length
* @param llamaCallback callback object to receive results.
*/
@DoNotStrip
public native int generate(String prompt, LlamaCallback llamaCallback);
public native int generate(String prompt, int seqLen, LlamaCallback llamaCallback);

/** Stop current generate() before it finishes. */
@DoNotStrip
Expand Down
Loading