|
12 | 12 | import com.facebook.jni.annotations.DoNotStrip;
|
13 | 13 | import com.facebook.soloader.nativeloader.NativeLoader;
|
14 | 14 | import com.facebook.soloader.nativeloader.SystemDelegate;
|
| 15 | +import java.io.File; |
15 | 16 | import org.pytorch.executorch.annotations.Experimental;
|
16 | 17 |
|
17 | 18 | /**
|
@@ -41,33 +42,49 @@ public class LlmModule {
|
41 | 42 | private static native HybridData initHybrid(
|
42 | 43 | int modelType, String modulePath, String tokenizerPath, float temperature, String dataPath);
|
43 | 44 |
|
| 45 | + /** |
| 46 | + * Constructs a LLM Module for a model with given type, model path, tokenizer, temperature, and |
| 47 | + * data path. |
| 48 | + */ |
| 49 | + public LlmModule( |
| 50 | + int modelType, String modulePath, String tokenizerPath, float temperature, String dataPath) { |
| 51 | + File modelFile = new File(modulePath); |
| 52 | + if (!modelFile.canRead() || !modelFile.isFile()) { |
| 53 | + throw new RuntimeException("Cannot load model path " + modulePath); |
| 54 | + } |
| 55 | + File tokenizerFile = new File(tokenizerPath); |
| 56 | + if (!tokenizerFile.canRead() || !tokenizerFile.isFile()) { |
| 57 | + throw new RuntimeException("Cannot load tokenizer path " + tokenizerPath); |
| 58 | + } |
| 59 | + mHybridData = initHybrid(modelType, modulePath, tokenizerPath, temperature, dataPath); |
| 60 | + } |
| 61 | + |
44 | 62 | /** Constructs a LLM Module for a model with given model path, tokenizer, temperature. */
|
45 | 63 | public LlmModule(String modulePath, String tokenizerPath, float temperature) {
|
46 |
| - mHybridData = initHybrid(MODEL_TYPE_TEXT, modulePath, tokenizerPath, temperature, null); |
| 64 | + this(MODEL_TYPE_TEXT, modulePath, tokenizerPath, temperature, null); |
47 | 65 | }
|
48 | 66 |
|
49 | 67 | /**
|
50 | 68 | * Constructs a LLM Module for a model with given model path, tokenizer, temperature and data
|
51 | 69 | * path.
|
52 | 70 | */
|
53 | 71 | public LlmModule(String modulePath, String tokenizerPath, float temperature, String dataPath) {
|
54 |
| - mHybridData = initHybrid(MODEL_TYPE_TEXT, modulePath, tokenizerPath, temperature, dataPath); |
| 72 | + this(MODEL_TYPE_TEXT, modulePath, tokenizerPath, temperature, dataPath); |
55 | 73 | }
|
56 | 74 |
|
57 | 75 | /** Constructs a LLM Module for a model with given path, tokenizer, and temperature. */
|
58 | 76 | public LlmModule(int modelType, String modulePath, String tokenizerPath, float temperature) {
|
59 |
| - mHybridData = initHybrid(modelType, modulePath, tokenizerPath, temperature, null); |
| 77 | + this(modelType, modulePath, tokenizerPath, temperature, null); |
60 | 78 | }
|
61 | 79 |
|
62 | 80 | /** Constructs a LLM Module for a model with the given LlmModuleConfig */
|
63 | 81 | public LlmModule(LlmModuleConfig config) {
|
64 |
| - mHybridData = |
65 |
| - initHybrid( |
66 |
| - config.getModelType(), |
67 |
| - config.getModulePath(), |
68 |
| - config.getTokenizerPath(), |
69 |
| - config.getTemperature(), |
70 |
| - config.getDataPath()); |
| 82 | + this( |
| 83 | + config.getModelType(), |
| 84 | + config.getModulePath(), |
| 85 | + config.getTokenizerPath(), |
| 86 | + config.getTemperature(), |
| 87 | + config.getDataPath()); |
71 | 88 | }
|
72 | 89 |
|
73 | 90 | public void resetNative() {
|
|
0 commit comments