Repository navigation
convert : fix Granite Switch block_count for MultiSwitch checkpoints - #30621
Conversation
Signed-off-by: Nigel Jones <[email protected]>
|
cc: @gabe-l-hart |
gabe-l-hart
left a comment
There was a problem hiding this comment.
One quick comment NIT, but otherwise this looks like a good quick solution. I confirmed that the updated version of ibm-granite/granite-switch-4.1-3b-preview no longer runs after conversion on master and that this conversion change effectively fixes the hparams and no further c++ side changes are needed to work with the converted file.
|
It's worth noting that ibm-granite/granite-switch-4.1-3b-preview was updated in-place, so older pulls of the model work with the existing conversion, but a fresh pull does not. |
|
Related! https://huggingface.co/blog/ibm-granite/granite-switch-4-1 (new Switch with decision adapter, guardian, and ASR baked in). We'll be working on extending for multimodal adapters soon |
Co-authored-by: Gabe Goodhart <[email protected]>
…MultiSwitch fix Current Granite Switch checkpoints use MultiSwitch, which reserves two cache slots. Every llama.cpp converter up to and including v0.7.0 writes a block count one too high for them, so the script's GGUF converted but llama-server refused to load it (ggml-org/llama.cpp#30617). Pin the converter to build b11675, the first with the fix (ggml-org/llama.cpp#30621). Verified from a cold cache on the current 3b revision: the script downloads, converts with transformers 5.20.0, and serves on a v0.6.0 llama-server; the GGUF's block_count is 40, matching blocks 0-39, and the example and the adapter functions run against it. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
…gml-org#30621) * convert : fix Granite Switch block_count for MultiSwitch checkpoints Signed-off-by: Nigel Jones <[email protected]> * Update granite.py Co-authored-by: Gabe Goodhart <[email protected]> --------- Signed-off-by: Nigel Jones <[email protected]> Co-authored-by: Gabe Goodhart <[email protected]>
…gml-org#30621) * convert : fix Granite Switch block_count for MultiSwitch checkpoints Signed-off-by: Nigel Jones <[email protected]> * Update granite.py Co-authored-by: Gabe Goodhart <[email protected]> --------- Signed-off-by: Nigel Jones <[email protected]> Co-authored-by: Gabe Goodhart <[email protected]>
…MultiSwitch fix Current Granite Switch checkpoints use MultiSwitch, which reserves two cache slots. Every llama.cpp converter up to and including v0.7.0 writes a block count one too high for them, so the script's GGUF converted but llama-server refused to load it (ggml-org/llama.cpp#30617). Pin the converter to build b11675, the first with the fix (ggml-org/llama.cpp#30621). Verified from a cold cache on the current 3b revision: the script downloads, converts with transformers 5.20.0, and serves on a v0.6.0 llama-server; the GGUF's block_count is 40, matching blocks 0-39, and the example and the adapter functions run against it. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
generative-computing#1736) * feat(backends): serve Granite Switch adapter functions on llama-server Granite Switch checkpoints could only run through vLLM or a local HuggingFace load. Pointing OpenAIBackend at a llama-server nearly worked: adapter activation and the document-free adapters were fine, but every document-based adapter returned "unanswerable" regardless of the documents, because llama-server drops the top-level documents field the intrinsic path sends, so the Switch chat template's documents variable never rendered. Mirror documents into chat_template_kwargs alongside the top-level field. vLLM folds both shapes into the same template context, so its behaviour is unchanged; llama-server reads the copy. Add scripts/start_llamacpp_switch.sh, which converts a Switch checkpoint to GGUF (working around the list-form extra_special_tokens that current transformers rejects) and serves it with llama-server --jinja on port 8081, next to the base-Granite server's 8080. Add an example that runs when that server is reachable and skips with an actionable reason otherwise, plus README and intrinsics docs. Closes generative-computing#1735. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(backends): send the intrinsic schema as response_format for llama-server The intrinsic path sent each io.yaml schema only as vLLM's own `structured_outputs` field. llama-server ignores that field and constrains decoding only from the OpenAI-standard `response_format`, so every adapter function ran unconstrained there. Also send the schema as `response_format`; vLLM folds it back into the same `structured_outputs.json`, and a caller's own `response_format` still wins. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(scripts): make the Switch converter install independent of cwd The converter's requirements pin transformers==4.57.6, which cannot load current Granite Switch tokenizers (tokenizer_class TokenizersBackend is a transformers 5 class). Run from inside the mellea repo, uv silently swapped the pin for mellea's own [tool.uv] override; run from anywhere else, the conversion failed after the multi-gigabyte download. Override transformers explicitly to the range mellea tests and run the install from the build cache so no surrounding project's uv settings change the resolve. The EXIT trap also removed every *.gguf.partial in the shared cache, which could delete a concurrent run's in-progress conversion for another model; it now removes only this run's file. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(formatters): accept identical documents in chat_template_kwargs GraniteChatCompletion rejected any request carrying documents both at the top level and inside chat_template_kwargs, which is now the shape OpenAIBackend sends for llama-server. Accept identical copies and drop the duplicate; differing copies are still rejected. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * test: gate the Switch llama.cpp example on its own backend marker answerability_llamacpp.py carried no backend marker, against the rule that e2e tests always name one: `llamacpp` probes the base-Granite server on 8080 and would wrongly skip it, so `-m` selection and backend grouping could not see it. Add a `llamacpp_switch` marker whose gate reuses the llama.cpp /props probe against LLAMACPP_SWITCH_BASE_URL (default 8081), and mark the example with it. Document both llama.cpp markers in the test README's backend table, which listed neither. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(examples): skip rather than fail when /models is not a model list The Switch llama.cpp example parsed the /models reply outside its skip guard, so a foreign server answering 200 with something other than an OpenAI model list failed the example instead of skipping it. Parse inside the guard. Also correct the documents-mirror comment, which said vLLM always gives the top-level field precedence; that holds on current vLLM, while 0.11 and earlier let chat_template_kwargs win. Reflow the llama-server paragraph in the intrinsics guide and note that io.yaml constraints now apply there too. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * test: pin that a caller's structured_outputs drives response_format The intrinsic path derives response_format from the merged extra_body, so a caller's own structured_outputs override is the schema mirrored. Pin it, and fix the llama.cpp gate docstring, which named the 8080 default even for the Switch gate. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(scripts): pin the Switch converter to a llama.cpp build with the MultiSwitch fix Current Granite Switch checkpoints use MultiSwitch, which reserves two cache slots. Every llama.cpp converter up to and including v0.7.0 writes a block count one too high for them, so the script's GGUF converted but llama-server refused to load it (ggml-org/llama.cpp#30617). Pin the converter to build b11675, the first with the fix (ggml-org/llama.cpp#30621). Verified from a cold cache on the current 3b revision: the script downloads, converts with transformers 5.20.0, and serves on a v0.6.0 llama-server; the GGUF's block_count is 40, matching blocks 0-39, and the example and the adapter functions run against it. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(scripts): let llama-server exit on its own after Ctrl-C A terminal Ctrl-C reaches the whole process group, so llama-server already had the interrupt when the script's EXIT trap sent it a second signal. It then logged "Received second interrupt, terminating immediately" and could trip a Metal teardown assert. After a signal, the trap now waits up to five seconds for the server to exit before signalling it; other exits still stop it at once. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: point the llama.cpp decisions example at the Switch server script decisions_llamacpp.py (from generative-computing#1742) predated this PR's conventions: it asked for llama.cpp from main, served the Switch model on 8080 (now the base-Granite server's port), read SWITCH_DECISIONS_BASE_URL, carried the `llamacpp` marker plus `skip`, and referred forward to this PR. It now reads LLAMACPP_SWITCH_BASE_URL (default 8081), carries `llamacpp_switch`, and skips with the start command when the server is absent or not serving granite-switch-4.1-8b, the checkpoint that embeds the decision adapter. The script's usage comment names that 8b rather than the 8b preview, which has no decision adapter. intrinsics.md gives the llama-server paragraph its own heading and links to it from the decisions section. A unit test pins that a decision request carries no response_format. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: make the llama-server route findable and say which model to serve The llama-server section sat at the end of the adapter-functions page, under "Composable adapter construction (advanced)", and never said which Switch checkpoint to serve. It is now its own section beside the local checkpoint section, with the prerequisites, one start command per adapter set (3b preview for RAG/core/guardian, released 8b for decisions), the port clash between them, and the backend snippet. The backend note, the decisions snippet, tutorial 09 and both example READMEs link to it. Also fixes the backend note's path to the Granite Switch examples, which pointed at a directory that does not exist. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(scripts): harden the Switch server script and test the llama.cpp gates Run the converter's inline Python with -I so a stray module in the caller's directory cannot shadow an import, add the llama.cpp remote only when it is missing rather than discarding every git error, reject a non-numeric ready timeout up front, and count the converter venv in the first-run download note. A new collection test pins that the llamacpp and llamacpp_switch markers each gate only on their own server; it fails if the Switch gate is removed. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: serve the 8b from IBM's published Switch GGUF IBM publishes granite-switch-4.1-8b-GGUF and -30b-GGUF, so decisions no longer need a local conversion: llama-server -hf with --alias serves the name the example checks for. The conversion script stays the route for the 3b preview, which has no published GGUF. Verified decisions and guardian-core against the published Q4_K_M. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: link the Switch examples by URL so the Docusaurus build passes The relative link to docs/examples/granite-switch/README.md resolves outside the docs site, which Docusaurus rejects as a broken link. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(openai): let a caller's response_format replace the io.yaml constraint vLLM layers response_format over structured_outputs, so a caller's json_object collided with the io.yaml json constraint and a caller's text left it in force. Drop the io.yaml structured_outputs when the caller sets response_format (unless they also set structured_outputs). Revert the GraniteChatCompletion duplicate-documents relaxation: nothing in Mellea validates the outgoing request through it. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: address review nits on the llama-server Switch route Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(openai): treat response_format=None as unset for intrinsics A caller passing response_format=None dropped the io.yaml structured_outputs and sent a null response_format, so adapters decoded unconstrained on both servers. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: name LLAMACPP_SWITCH_BASE_URL and define MODEL in the llama-server snippet Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: state llama-server v0.6.0 as the minimum for Switch GGUFs Current MultiSwitch GGUFs are only known to load on v0.6.0 and newer. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(scripts): key the cached Switch GGUF on the converter revision Bumping LLAMA_CPP_REVISION previously reused a GGUF written by the older converter, which llama-server may refuse to load. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(openai): honour a caller's response_format passed through extra_body The SDK merges extra_body over the typed kwargs, so a response_format in model_options["extra_body"] skipped the precedence check: the io.yaml structured_outputs stayed in the request and the mirrored response_format was sent too, which vLLM rejects. Resolve the caller's format from both places before dropping the io.yaml constraint and before mirroring it. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * fix(scripts): write the Switch GGUF to a per-run partial file Concurrent runs for the same model shared one .partial file and could write a corrupt GGUF that the cache check then accepted. Name the file with the pid, remove partials whose run has gone, and keep the final mv as an atomic rename. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * test: make the Switch skip reason name neither example's server The two llamacpp_switch examples need different checkpoints on the same default port, so the reason now points at LLAMACPP_SWITCH_BASE_URL and each example's docstring instead of one start command. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> --------- Signed-off-by: Nigel Jones <[email protected]>
Overview
GGUF files converted from newer Granite Switch checkpoints fail to load with the error:
The conversion itself succeeds and writes every real decoder layer.
Unfortunate one metadata value is wrong:
GraniteSwitchModelassumes the checkpoint's weightless switch owns exactly one KV cache slot and setsblock_count = num_hidden_layers - 1.The newer switch generation (MultiSwitch) owns two slots, so
num_hidden_layerscounts real layers plus two, and the storedgraniteswitch.block_countcomes out one too high. So the loader asks for a block that was never written.This PR derives the block count from the
model.layers.Ntensors actually present in the checkpoint instead of assuming a fixed offset. That is the count the runtime already expects:granite-switch.cppsizes the model type from it and adds the router layer beyondn_layerat load time.Affected are newer-generation Granite Switch checkpoints, for example
ibm-granite/granite-switch-4.1-3b-preview. Older SingleSwitch-generation checkpoints convert identically before and after this change.Fixes #30617
Additional information
llama-serverfails to load it with the error above; with the patch it loads.granite-switch.cpp'screate_tensorcalls.generative-computing/granite-switch,num_cache_layers), which buildsnum_hidden_layers - num_cache_layersdecoder layers.block_count -= 2 if "ms_code_m" in self.hparams else 1) also works today but breaks again the next time the engine's slot budget changes.NOTE that the
flakepre-commit was skipped (SKIP=flake8) due to dependency issues/crashesRequirements