Skip to content

Commit fa5f2eb

Browse files
committed
[LlamaDemo] skip some tokens
1 parent 1c2b7ba commit fa5f2eb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/MainActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public void onResult(String result) {
9090
if (result.equals(PromptFormat.getStopToken(mCurrentSettingsFields.getModelType()))) {
9191
return;
9292
}
93+
if (PromptFormat.shouldSkipToken(mCurrentSettingsFields.getModelType(), result)) {
94+
return;
95+
}
9396
if (result.equals("\n\n") || result.equals("\n")) {
9497
if (!mResultMessage.getText().isEmpty()) {
9598
mResultMessage.appendText(result);

examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/PromptFormat.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ public static String getStopToken(ModelType modelType) {
8686
}
8787
}
8888

89+
public static boolean shouldSkipToken(ModelType modelType, String token) {
90+
switch (modelType) {
91+
case QWEN_3:
92+
return token.equals("<|im_end|>");
93+
default:
94+
return false;
95+
}
96+
}
97+
8998
public static String getLlavaPresetPrompt() {
9099
return "A chat between a curious human and an artificial intelligence assistant. The assistant"
91100
+ " gives helpful, detailed, and polite answers to the human's questions. USER: ";

0 commit comments

Comments
 (0)