Skip to content

Commit

Permalink
Do not require Proto types in public API.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 721462409
  • Loading branch information
schmidt-sebastian authored and copybara-github committed Jan 30, 2025
1 parent 96a7dd5 commit 7bdac30
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@

/** LlmInference Task Java API */
public class LlmInference implements AutoCloseable {
/** The backend to use for inference. */
public enum Backend {
/** Use the default backend for the model. */
DEFAULT,
/** Use the CPU backend for inference. */
CPU,
/** Use the GPU backend for inference. */
GPU
}

private static final String STATS_TAG = LlmInference.class.getSimpleName();

private static final int NUM_DECODE_STEPS_PER_SYNC = 3;
Expand Down Expand Up @@ -57,8 +67,18 @@ public static LlmInference createFromOptions(Context context, LlmInferenceOption
modelSettings.setVisionModelSettings(visionModelSettings.build());
}

if (options.llmPreferredBackend().isPresent()) {
modelSettings.setLlmPreferredBackend(options.llmPreferredBackend().get());
if (options.preferredBackend().isPresent()) {
switch (options.preferredBackend().get()) {
case DEFAULT:
modelSettings.setLlmPreferredBackend(LlmPreferredBackend.DEFAULT);
break;
case CPU:
modelSettings.setLlmPreferredBackend(LlmPreferredBackend.CPU);
break;
case GPU:
modelSettings.setLlmPreferredBackend(LlmPreferredBackend.GPU);
break;
}
}

return new LlmInference(context, STATS_TAG, modelSettings.build(), options.resultListener());
Expand Down Expand Up @@ -217,8 +237,8 @@ public abstract static class Builder {
/** Sets the model options to use for vision modality. */
public abstract Builder setVisionModelOptions(VisionModelOptions visionModelOptions);

/** Sets the preferred backend to use for the LLM model. */
public abstract Builder setLlmPreferredBackend(LlmPreferredBackend llmPreferredBackend);
/** Sets the preferred backend to use for inference. */
public abstract Builder setPreferredBackend(Backend preferredBackend);

abstract LlmInferenceOptions autoBuild();

Expand Down Expand Up @@ -256,8 +276,8 @@ public final LlmInferenceOptions build() {
/** The model options to for vision modality. */
public abstract Optional<VisionModelOptions> visionModelOptions();

/** Returns the preferred backend to use for the LLM model. */
public abstract Optional<LlmPreferredBackend> llmPreferredBackend();
/** Returns the preferred backend to use for inference. */
public abstract Optional<Backend> preferredBackend();

/** Returns a new builder with the same values as this instance. */
public abstract Builder toBuilder();
Expand Down

0 comments on commit 7bdac30

Please sign in to comment.