Skip to content

Commit c0132b1

Browse files
kirklandsignDannyYuyang-quic
authored andcommitted
[Android] Use new Llm package API
Differential Revision: D71633438 Pull Request resolved: pytorch#9495
1 parent 3405e7a commit c0132b1

File tree

10 files changed

+32
-278
lines changed

10 files changed

+32
-278
lines changed

examples/demo-apps/android/LlamaDemo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Optional Parameters:
7575

7676
```java
7777
// Upon returning to the Main Chat Activity
78-
mModule = new LlamaModule(
78+
mModule = new LlmModule(
7979
ModelUtils.getModelCategory(mCurrentSettingsFields.getModelType()),
8080
modelPath,
8181
tokenizerPath,

examples/demo-apps/android/LlamaDemo/app/src/androidTest/java/com/example/executorchllamademo/PerfTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import java.util.List;
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
23-
import org.pytorch.executorch.LlamaCallback;
24-
import org.pytorch.executorch.LlamaModule;
23+
import org.pytorch.executorch.extension.llm.LlmCallback;
24+
import org.pytorch.executorch.extension.llm.LlmModule;
2525

2626
@RunWith(AndroidJUnit4.class)
27-
public class PerfTest implements LlamaCallback {
27+
public class PerfTest implements LlmCallback {
2828

2929
private static final String RESOURCE_PATH = "/data/local/tmp/llama/";
3030
private static final String TOKENIZER_BIN = "tokenizer.bin";
@@ -41,7 +41,7 @@ public void testTokensPerSecond() {
4141
.filter(file -> file.getName().endsWith(".pte"))
4242
.forEach(
4343
model -> {
44-
LlamaModule mModule = new LlamaModule(model.getPath(), tokenizerPath, 0.8f);
44+
LlmModule mModule = new LlmModule(model.getPath(), tokenizerPath, 0.8f);
4545
// Print the model name because there might be more than one of them
4646
report("ModelName", model.getName());
4747

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@
4949
import java.util.List;
5050
import java.util.concurrent.Executor;
5151
import java.util.concurrent.Executors;
52-
import org.pytorch.executorch.LlamaCallback;
53-
import org.pytorch.executorch.LlamaModule;
52+
import org.pytorch.executorch.extension.llm.LlmCallback;
53+
import org.pytorch.executorch.extension.llm.LlmModule;
5454

55-
public class MainActivity extends AppCompatActivity implements Runnable, LlamaCallback {
55+
public class MainActivity extends AppCompatActivity implements Runnable, LlmCallback {
5656
private EditText mEditTextMessage;
5757
private ImageButton mSendButton;
5858
private ImageButton mGalleryButton;
5959
private ImageButton mCameraButton;
6060
private ListView mMessagesView;
6161
private MessageAdapter mMessageAdapter;
62-
private LlamaModule mModule = null;
62+
private LlmModule mModule = null;
6363
private Message mResultMessage = null;
6464
private ImageButton mSettingsButton;
6565
private TextView mMemoryView;
@@ -124,7 +124,7 @@ private void setLocalModel(String modelPath, String tokenizerPath, float tempera
124124
}
125125
long runStartTime = System.currentTimeMillis();
126126
mModule =
127-
new LlamaModule(
127+
new LlmModule(
128128
ModelUtils.getModelCategory(
129129
mCurrentSettingsFields.getModelType(), mCurrentSettingsFields.getBackendType()),
130130
modelPath,
@@ -714,7 +714,7 @@ private void onModelRunStopped() {
714714
// Scroll to bottom of the list
715715
mMessagesView.smoothScrollToPosition(mMessageAdapter.getCount() - 1);
716716
// After images are added to prompt and chat thread, we clear the imageURI list
717-
// Note: This has to be done after imageURIs are no longer needed by LlamaModule
717+
// Note: This has to be done after imageURIs are no longer needed by LlmModule
718718
mSelectedImageUri = null;
719719
promptID++;
720720
Runnable runnable =

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
import android.os.Looper;
1414
import android.os.Message;
1515
import androidx.annotation.NonNull;
16-
import org.pytorch.executorch.LlamaCallback;
17-
import org.pytorch.executorch.LlamaModule;
16+
import org.pytorch.executorch.extension.llm.LlmCallback;
17+
import org.pytorch.executorch.extension.llm.LlmModule;
1818

1919
/** A helper class to handle all model running logic within this class. */
20-
public class ModelRunner implements LlamaCallback {
21-
LlamaModule mModule = null;
20+
public class ModelRunner implements LlmCallback {
21+
LlmModule mModule = null;
2222

2323
String mModelFilePath = "";
2424
String mTokenizerFilePath = "";
@@ -45,7 +45,7 @@ public class ModelRunner implements LlamaCallback {
4545
mTokenizerFilePath = tokenizerFilePath;
4646
mCallback = callback;
4747

48-
mModule = new LlamaModule(mModelFilePath, mTokenizerFilePath, 0.8f);
48+
mModule = new LlmModule(mModelFilePath, mTokenizerFilePath, 0.8f);
4949
mHandlerThread = new HandlerThread("ModelRunner");
5050
mHandlerThread.start();
5151
mHandler = new ModelRunnerHandler(mHandlerThread.getLooper(), this);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {}
189189
public void afterTextChanged(Editable s) {
190190
mSetTemperature = Double.parseDouble(s.toString());
191191
// This is needed because temperature is changed together with model loading
192-
// Once temperature is no longer in LlamaModule constructor, we can remove this
192+
// Once temperature is no longer in LlmModule constructor, we can remove this
193193
mSettingsFields.saveLoadModelAction(true);
194194
saveSettings();
195195
}

extension/android/BUCK

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ fb_android_library(
2323
fb_android_library(
2424
name = "executorch_llama",
2525
srcs = [
26-
"src/main/java/org/pytorch/executorch/LlamaCallback.java",
27-
"src/main/java/org/pytorch/executorch/LlamaModule.java",
2826
"src/main/java/org/pytorch/executorch/extension/llm/LlmCallback.java",
2927
"src/main/java/org/pytorch/executorch/extension/llm/LlmModule.java",
3028
],

extension/android/src/main/java/org/pytorch/executorch/LlamaCallback.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

extension/android/src/main/java/org/pytorch/executorch/LlamaModule.java

Lines changed: 0 additions & 207 deletions
This file was deleted.

0 commit comments

Comments
 (0)