Skip to content

Fix LlamaDemo temperature, lifecycle, and LLM memory support#239

Open
psiddh wants to merge 2 commits into
mainfrom
fix/llama-demo-improvements
Open

Fix LlamaDemo temperature, lifecycle, and LLM memory support#239
psiddh wants to merge 2 commits into
mainfrom
fix/llama-demo-improvements

Conversation

@psiddh
Copy link
Copy Markdown
Contributor

@psiddh psiddh commented May 24, 2026

Summary

  • fbjni 0.7.0: Required for compatibility with main_exp AAR builds.
  • largeHeap="true": LLM models with 4096 context windows can use 2.5GB+ RSS. Enables Android's large heap allocation for the app process.

Context

These fixes were discovered while validating multi-turn conversation support with Qwen3 4B (INT8-INT4) on Samsung Galaxy S23 with max_context_length=4096. Note that the temperature needed to be set to say 0.5, o/w it made all models appear broken by generating 0-1 tokens.

Test plan

  • Build APK with ./gradlew assembleDebug
  • Load Llama 3.2 1B or Qwen3 4B model with XNNPACK backend
  • Verify model generates multi-token responses (temperature fix)
  • Verify multi-turn conversation works with KV cache accumulation
  • Verify no resource leaks on app close/rotate (onCleared fix)

Authored with Claude.

…support

- Change DEFAULT_TEMPERATURE from 0.0 to 0.6 to prevent greedy decoding
  from hitting EOS token immediately on first generated token
- Add onCleared() lifecycle handler to ChatViewModel for proper Module
  resource cleanup when ViewModel is destroyed
- Update fbjni to 0.7.0 for main_exp AAR compatibility
- Enable largeHeap in AndroidManifest for large LLM model support

Authored with Claude.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 24, 2026
@psiddh psiddh requested a review from kirklandsign May 24, 2026 23:17
…mperature

- Remove onCleared() override — LlmModule.close() was added in the
  Kotlin conversion (#19211) but the published Maven AAR still ships
  the old Java version without it
- Revert DEFAULT_TEMPERATURE to 0.0 — users can set temperature via
  the UI settings; no need to change the default

Authored with Claude.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant