Skip to content

Commit d4afbe7

Browse files
cmodi-metafacebook-github-bot
authored andcommitted
Show loading model UI during model switch (#5691)
Summary: Pull Request resolved: #5691 Destructing a model takes about 5 seconds of time. Previously, if the user switched models then "loading model..." would only show 5 seconds after the model was destructed. To help UX we will show "loading model..." before we we destroy the model. This way the user will know that app has ack'd that a model refresh needs to happen. Reviewed By: kirklandsign Differential Revision: D62512275 fbshipit-source-id: 29a808ce1ded125752f846f3a7cd3e3d0e86854a
1 parent 61c421f commit d4afbe7

File tree

1 file changed

+6
-4
lines changed
  • examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ public void onStats(float tps) {
107107
}
108108

109109
private void setLocalModel(String modelPath, String tokenizerPath, float temperature) {
110-
if (mModule != null) {
111-
mModule.resetNative();
112-
mModule = null;
113-
}
114110
Message modelLoadingMessage = new Message("Loading model...", false, MessageType.SYSTEM, 0);
115111
ETLogging.getInstance().log("Loading model " + modelPath + " with tokenizer " + tokenizerPath);
116112
runOnUiThread(
@@ -119,6 +115,12 @@ private void setLocalModel(String modelPath, String tokenizerPath, float tempera
119115
mMessageAdapter.add(modelLoadingMessage);
120116
mMessageAdapter.notifyDataSetChanged();
121117
});
118+
if (mModule != null) {
119+
ETLogging.getInstance().log("Start deallocating existing module instance");
120+
mModule.resetNative();
121+
mModule = null;
122+
ETLogging.getInstance().log("Completed deallocating existing module instance");
123+
}
122124
long runStartTime = System.currentTimeMillis();
123125
mModule =
124126
new LlamaModule(

0 commit comments

Comments
 (0)