Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 5 min read How-to mediumAdept

“Llama 3.2 in Keras”

Keras (via keras_hub) loads Llama 3.2 directly from standard safetensors Hugging Face checkpoints with on-the-fly conversion, so it has worked since day one. A tour of the workflow covers the multi-backend switch (JAX, PyTorch, TensorFlow), tokenizer-included generate/fit on raw strings, chat formatting for the Instruct model, preprocessor and backbone access, LoRA fine-tuning, and uploading presets back to the Hub. For larger models like Llama 3.1 8B, Keras's ModelParallel distribution with a device mesh and layout map shards weights across TPU/GPU cores. A custom layout map cut epoch time from 62s to 54s on an 8-core TPU v5e.

Related posts

  • Announcing New Hugging Face and KerasHub integration

    Hugging Face mediumAdept

    KerasHub can now load Transformers-format checkpoints from the Hugging Face Hub directly, through a shared model save format. Initial support covers Gemma 1 and 2, Llama 3 and PaliGemma, and the models can run on TensorFlow, JAX or PyTorch backends. Loading works by mapping the Transformers JSON config, tokenizer and safetensors weight names onto KerasHub's equivalent architecture code, which also allows conversion in the other direction. Code examples show `from_preset("hf://...")` loading, text generation, setting bfloat16 precision and switching to the JAX backend.

  • How good are LLMs at fixing their mistakes? A chatbot arena experiment with Keras and TPUs

    Hugging Face mediumAdept

    Small instruction-tuned LLMs were given a calendar-assistant task that translates spoken requests into single-line Python API calls, then corrected in plain English when they made mistakes. Gemma 2 9B and Llama 3.1 8B completed the dialog reliably and fixed errors when told, while 1–3B models, Vicuna and Mistral 7B often failed or compounded mistakes. CodeGemma had sticky recurring errors, and online Gemini was not better despite its size. The test harness is a Gradio app on Hugging Face Spaces that shards eight models across a TPU v5e 2x4 (128GB) using Keras layout maps on JAX, keeping seven or eight sub-10B models in memory at once in bfloat16.

  • Tricks from OpenAI gpt-oss YOU 🫵 can use with transformers

    Hugging Face hardMaster

    Hugging Face upgraded transformers to support OpenAI's gpt-oss models, and most of the new features carry over to other models. These include pre-built kernels downloaded from the Hub (Liger RMSNorm, MegaBlocks MoE, Flash Attention 3 with attention sinks), native MXFP4 4-bit quantization via Triton kernels, tensor and expert parallelism, dynamic sliding window caching, continuous batching with paged attention, and faster loading. MXFP4 stores E2M1 values in 32-element blocks with shared scales. That lets gpt-oss-20B run in about 16 GB of VRAM and 120B in about 80 GB, versus roughly 4× the memory in the bf16 fallback. Benchmarks show the custom and MXFP4 kernels pay off mainly at larger batch sizes.

  • Transformers now runs llama.cpp quants

    Hugging Face mediumAdept

    Hugging Face transformers can now load GGUF (llama.cpp) quantized checkpoints via `from_pretrained(..., gguf_file=...)` and serve them through `transformers serve` with an OpenAI-compatible API. Weights stay packed on Apple Silicon, and ggml's Metal kernels are reused via the `kernels` library for quantized matmul, fused RMSNorm, flash attention, gated delta nets and MoE top-k routing. Two `generate` changes, dropping all-ones padding masks and deferring the stopping check asynchronously, cut CPU-GPU synchronization for all models. Benchmarks on an M2 Max show throughput close to llama-bench for Qwen3.5 dense and MoE checkpoints, though llama.cpp remains the recommended engine for pure local inference. The initial packed path is MPS-only, and padded batching is still slower.

  • Native-speed vLLM transformers modeling backend

    Hugging Face hardMaster

    The transformers modeling backend in vLLM now matches or beats vLLM's hand-written native implementations in throughput. Benchmarks covered Qwen3-4B on one GPU, Qwen3-32B with tensor parallelism, and Qwen3-235B FP8 MoE with data and expert parallelism on 8×H100. The backend uses torch.fx static analysis to find known patterns, then rewrites the model source via AST to swap in fused vLLM kernels such as QKVParallelLinear, MergedColumnParallelLinear and expert-parallel MoE ops. It also infers TP/PP plans while staying compatible with torch.compile and CUDA Graphs. Any compliant transformers model gets this with `--model-impl transformers`, except linear-attention models and custom Hub-code models.

The quest for software engineering knowledge.

Look:
Layout: