Skip to content

Fix broken bindings and add missing llama.cpp API coverage with examples - #4

Merged
nbeerbower merged 3 commits into
mainfrom
claude/fix-llama-bindings-examples-O3Fa2
Feb 7, 2026
Merged

Fix broken bindings and add missing llama.cpp API coverage with examples#4
nbeerbower merged 3 commits into
mainfrom
claude/fix-llama-bindings-examples-O3Fa2

Conversation

@nbeerbower

Copy link
Copy Markdown
Contributor
  • Fix batch struct size bug: allocate 56 bytes (not 48) for llama_batch
    struct to correctly account for all 6 pointer fields after n_tokens
  • Add missing FFI declarations: grammar sampling, logit bias, infill/FIM,
    LoRA adapters, state save/load, pooling type, vocab score/attr,
    model quantization
  • Add high-level wrappers for all new bindings with ergonomic APIs
  • Add constants for token attributes and quantization types
  • Add 7 new examples demonstrating different capabilities:
    • embeddings.hml: text embeddings with cosine similarity
    • chat_template.hml: proper chat template formatting
    • grammar.hml: GBNF grammar-constrained JSON generation
    • tokenizer.hml: vocabulary and tokenization exploration
    • streaming.hml: streaming generation with performance metrics
    • infill.hml: code fill-in-the-middle (FIM) completion
    • model_info.hml: model metadata and system inspection
  • Update README with new API reference and example documentation

https://claude.ai/code/session_01PQRPJWjp2HfT41sKmVaSsy

- Fix batch struct size bug: allocate 56 bytes (not 48) for llama_batch
  struct to correctly account for all 6 pointer fields after n_tokens
- Add missing FFI declarations: grammar sampling, logit bias, infill/FIM,
  LoRA adapters, state save/load, pooling type, vocab score/attr,
  model quantization
- Add high-level wrappers for all new bindings with ergonomic APIs
- Add constants for token attributes and quantization types
- Add 7 new examples demonstrating different capabilities:
  - embeddings.hml: text embeddings with cosine similarity
  - chat_template.hml: proper chat template formatting
  - grammar.hml: GBNF grammar-constrained JSON generation
  - tokenizer.hml: vocabulary and tokenization exploration
  - streaming.hml: streaming generation with performance metrics
  - infill.hml: code fill-in-the-middle (FIM) completion
  - model_info.hml: model metadata and system inspection
- Update README with new API reference and example documentation

https://claude.ai/code/session_01PQRPJWjp2HfT41sKmVaSsy
- Expand test_basic.hml with 40+ assertions covering constants,
  sampler creation/chain/introspection, and backend functions
  (all without requiring a model file)
- Add test_model.hml with comprehensive model-dependent tests:
  model info, vocab, tokenization round-trips, decode, sampling,
  KV cache, chat templates, grammar, logit bias, generation
- Add scripts/download_test_model.sh to fetch a ~15MB TinyStories
  model from HuggingFace for quick testing
- Add models/ to .gitignore
- Update CI to validate all new example files

https://claude.ai/code/session_01PQRPJWjp2HfT41sKmVaSsy
- Split test step into basic tests (no model) and model tests
- Download ~15MB TinyStories Q4_0 model in CI for model-dependent tests
- Model download and tests only run when Hemlock compiler is available
- Lint job also checks download_test_model.sh syntax

https://claude.ai/code/session_01PQRPJWjp2HfT41sKmVaSsy
@nbeerbower
nbeerbower merged commit 80eb0b8 into main Feb 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants