[litertlm] Update LiteRT-LM Kotlin Backend API to a sealed class#1546
Merged
copybara-service[bot] merged 1 commit intomainfrom Mar 6, 2026
Merged
[litertlm] Update LiteRT-LM Kotlin Backend API to a sealed class#1546copybara-service[bot] merged 1 commit intomainfrom
copybara-service[bot] merged 1 commit intomainfrom
Conversation
8e89ddc to
5c3db42
Compare
This change refactors the `Backend` API in `Config.kt` from an enum
to a sealed class to support backend-specific configurations directly
within the backend definition.
**Key changes include:**
* **Backend Sealed Class:** `Backend` is now a sealed class with three
variants: `CPU(val numThreads: Int)`, `NPU()`,
and `GPU()`.
* **JNI Configuration:** Updated `LiteRtLmJni.nativeCreateEngine` and
`litertlm.cc` to accept and process the `num_threads` parameter, which
is mapped to `number_of_threads` in the C++ `CpuConfig`.
* **Tests & Examples Migration:** Updated all test cases (e.g.,
`SessionTest`, `DeviceTest`, `BaseDeviceTest`) and example scripts
(`Main.kt`, `ToolMain.kt`, `BenchmarkMain.kt`) to instantiate the new
`Backend.CPU()` and `Backend.NPU(...)` data classes.
LiteRT-LM-PiperOrigin-RevId: 879674985
5c3db42 to
ff00423
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[litertlm] Update LiteRT-LM Kotlin Backend API to a sealed class
This change refactors the
BackendAPI inConfig.ktfrom an enumto a sealed class to support backend-specific configurations directly
within the backend definition.
Key changes include:
Backendis now a sealed class with threevariants:
CPU(val numThreads: Int),NPU(),and
GPU().LiteRtLmJni.nativeCreateEngineandlitertlm.ccto accept and process thenum_threadsparameter, whichis mapped to
number_of_threadsin the C++CpuConfig.SessionTest,DeviceTest,BaseDeviceTest) and example scripts(
Main.kt,ToolMain.kt,BenchmarkMain.kt) to instantiate the newBackend.CPU()andBackend.NPU(...)data classes.