@dr33m/react-native-litert-lm 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -728,6 +728,9 @@ class HybridLiteRTLM : HybridLiteRTLMSpec() {
|
|
|
728
728
|
* held and believed in.
|
|
729
729
|
*/
|
|
730
730
|
fun releaseUnderMemoryPressure() {
|
|
731
|
+
// Nothing loaded is nothing to free, and saying otherwise turns one
|
|
732
|
+
// emergency into a page of identical warnings.
|
|
733
|
+
if (engine == null) return
|
|
731
734
|
Log.w(TAG, "Releasing engine under memory pressure; instance stays reloadable")
|
|
732
735
|
cleanupInternal()
|
|
733
736
|
}
|
|
@@ -736,6 +739,9 @@ class HybridLiteRTLM : HybridLiteRTLMSpec() {
|
|
|
736
739
|
Log.d(TAG, "Closing resources")
|
|
737
740
|
isClosed = true
|
|
738
741
|
cleanupInternal()
|
|
742
|
+
// A closed instance can never load again, so it has no business being
|
|
743
|
+
// woken by the next memory emergency.
|
|
744
|
+
LiteRTLMRegistry.unregister(this)
|
|
739
745
|
}
|
|
740
746
|
|
|
741
747
|
private fun cleanupInternal() {
|
|
@@ -960,7 +966,17 @@ class HybridLiteRTLM : HybridLiteRTLMSpec() {
|
|
|
960
966
|
|
|
961
967
|
val userMsg = LiteRTMessage.user(Contents.of(contents))
|
|
962
968
|
|
|
963
|
-
|
|
969
|
+
// Always stated, never omitted.
|
|
970
|
+
//
|
|
971
|
+
// `enable_thinking` is a chat-template variable, not a Gemma
|
|
972
|
+
// feature, and templates test it as "defined and false". Qwen3's
|
|
973
|
+
// is exactly that shape, so leaving the key out is not the same
|
|
974
|
+
// as setting it to false: undefined falls through to the
|
|
975
|
+
// template's own default, which for a reasoning model is to
|
|
976
|
+
// reason. Omitting it meant thinking could be turned on but
|
|
977
|
+
// never off, and the reasoning arrived inline in the answer.
|
|
978
|
+
val extraContext: Map<String, String> =
|
|
979
|
+
mapOf("enable_thinking" to enableThinking.toString())
|
|
964
980
|
|
|
965
981
|
if (onToken != null) {
|
|
966
982
|
// ── Streaming path ────────────────────────────────────────────────
|
|
@@ -21,6 +21,23 @@ object LiteRTLMRegistry {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Drop a retired instance.
|
|
26
|
+
*
|
|
27
|
+
* The set holds weak keys, so a dead instance does leave eventually — but
|
|
28
|
+
* only once GC gets to it, and until then it is still iterated and still
|
|
29
|
+
* logged against. Every `loadModel()` mints a fresh HybridLiteRTLM, so a
|
|
30
|
+
* few reloads were enough for one memory emergency to report five engines
|
|
31
|
+
* released when only the last of them held anything. Closing is a definite
|
|
32
|
+
* end, so it is a better moment to forget an instance than a collection
|
|
33
|
+
* that may not have happened yet.
|
|
34
|
+
*/
|
|
35
|
+
fun unregister(instance: HybridLiteRTLM) {
|
|
36
|
+
synchronized(instances) {
|
|
37
|
+
instances.remove(instance)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
24
41
|
/**
|
|
25
42
|
* Whether a trim level is a real emergency worth dropping engines for.
|
|
26
43
|
*
|