--- license: apache-2.0 library_name: transformers base_model: ibm-granite/granite-4.2-3b base_model_relation: finetune pipeline_tag: text-generation language: - en - zh tags: - text-generation - sft - thinking - html-card - full-finetune - granite --- # granite-4.2-3b · HTML (think) A full-parameter SFT of **[ibm-granite/granite-4.2-3b](https://huggingface.co/ibm-granite/granite-4.2-3b)** (3.66B dense, Apache-2.0) for structured HTML card generation. Given any instruction, the model first emits a reasoning block (closed by ``) and then produces the normalized HTML card body. ## Model Summary | Item | Value | |---|---| | Base model | `ibm-granite/granite-4.2-3b` (bf16, Apache-2.0) | | Training scope | Full-parameter SFT (embeddings and `lm_head` frozen) | | Training data | Mario-HTML SFT, 830 examples (709 CoT-think + 121 direct), three-field `user`/`think`/`body` format | | Learning rate / epochs | 2e-5 / 1.3 epochs (234 steps) | | Sequence length / budget | 8192 / 16384 | | Seed | 42 | | Optimizer stack | Liger kernel, bf16 | | Weight file | Single `model.safetensors` (6.82 GiB), sha256 `c2f0e856ecaa10bd925609f2ec64cfdf94f5afa2d7654c79bc516f959ce51f79` | --- ## 🖼️ Demo Rendered by the bundled WebUI (`webui/`) — the collapsed *Chain of Thought* panel on top, the raw model output rendered as an HTML card below it, unmodified. `who is the presidency of US now?` WebUI chat demo: the Chain of Thought panel above shows the model reasoning about which president to name, and the answer below renders as an HTML card with a blue callout, a Joe Biden detail card, and a Context Note panel; the status bar shows 7.66s, 61.4 tok/s and 470 tokens --- ## Observed behaviour Measured with 19 generation probes: - **Think closure 17/17** — with thinking enabled, every reasoning block closed properly before the body started. The reasoning style is data-driven ("The user wants…"), not a base-model artefact. - **Closure needs in-distribution reinforcement.** Under the same lr/epoch/seed: no-think data × full-parameter training welded the think tag on (86% unclosed); no-think data × attention-only training kept it but closed unreliably (~80–90%). This repo is the think-data × full-parameter variant. - **Body** is a normalized HTML card (`ai-view` structure), renderable directly by the bundled WebUI. --- ## Deployment ```bash vllm serve --max-model-len 65536 --gpu-memory-utilization 0.9 ``` OpenAI-compatible endpoint. The bundled `chat_template.jinja` implements the ChatML-style format with `` tags: - `enable_thinking=true` → the prompt is prefixed with an open `` and the model reasons first. - `enable_thinking=false` → the template pre-closes an empty think block (``) and the model answers directly. ### Chat template ```python from transformers import AutoTokenizer tok = AutoTokenizer.from_pretrained("wesjos/granite-4.2-3b-HTML") text = tok.apply_chat_template( [{"role": "user", "content": "Make me a card for a coffee shop."}], tokenize=False, add_generation_prompt=True, enable_thinking=True, ) ``` --- ## 🖥️ Bundled WebUI A single-file FastAPI chat UI lives in [`webui/`](https://huggingface.co/wesjos/granite-4.2-3b-HTML/tree/main/webui). It splits the `` stream into a collapsible *Chain of Thought* panel and renders the answer body as an HTML card on a canvas. ```bash # 1. serve the model vllm serve . --served-model-name granite-4.2-3b-HTML \ --max-model-len 65536 --gpu-memory-utilization 0.9 # 2. serve the UI cd webui pip install -r requirements.txt ./run_webui.sh # → http://localhost:8791 ``` It is model-agnostic: point `api_url` in `webui/config.json` at any OpenAI-compatible `/v1` endpoint. See [`webui/README.md`](https://huggingface.co/wesjos/granite-4.2-3b-HTML/blob/main/webui/README.md) for the full file list and options. A GGUF build of this model is available at **[`wesjos/granite-4.2-3b-HTML-GGUF`](https://huggingface.co/wesjos/granite-4.2-3b-HTML-GGUF)** (Q8_0 + Q4_K_M). --- ## Notes - `config.json` additionally carries the legacy top-level `rope_theta` / `rope_scaling` / `torch_dtype` keys and `use_cache: true`, so the repo loads cleanly on both `transformers` 4.x and 5.x. - The tokenizer files are byte-identical to the base model's tokenizer (`tokenizer.json` sha256 `883975314d58743726347caaf2c32ac89afd5ad57222cffbc4f052f2ab27b2d7`); `vocab.json`, `merges.txt` and `special_tokens_map.json` are included for `transformers` 4.x compatibility. ## License and attribution Apache-2.0. This is an unofficial fine-tune of the IBM Granite model family; it is not endorsed by or affiliated with IBM. The base model `ibm-granite/granite-4.2-3b` is licensed under Apache-2.0.