Views
No views yet
Experimental. NVFP4 is a Blackwell (RTX 50xx / GB2xx) native format. Inference on older hardware may fall back to emulated paths or fail.
zai-org/GLM-4.6V-Flash using compressed-tensors NVFP4, with the entire multimodal vision stack (model.visual.*) preserved in BF16 and verified with end-to-end image understanding tests.Mitchins/GLM-4.6V-Flash-FP8-Block128 for the more broadly compatible FP8 variant.| Component | Quantization | Notes |
|---|---|---|
model.language_model.layers.* | NVFP4 (W4A8, per-block microscale) | All linear projections |
model.visual.* | BF16 (unchanged) | Vision encoder + merger/projector |
model.language_model.embed_tokens | BF16 (unchanged) | Embedding table |
lm_head | BF16 (unchanged) | Logit projection |
wikitext-2-raw-v1 (train split), max 512 tokens, concatenated. Text-only calibration is sufficient because the vision stack is excluded from quantization.| Size | |
|---|---|
| Base model (BF16) | ~18 GB |
| FP8-Block128 | ~12.4 GB |
| This repo (NVFP4) | 8.9 GB |
transformers==4.57.6llmcompressor==0.10.0.1vllm==0.19.0torch==2.10.0+cu128CUDA 12.8"The image shows the Sydney Harbour Bridge at night. The bridge is illuminated with lights along the bridge. The background shows the city skyline with buildings illuminated at night. The Sydney Harbour Bridge is a large steel arch bridge that spans Sydney Harbour."
vllm serve Mitchins/GLM-4.6V-Flash-NVFP4-BF16Vision --dtype bfloat16quantization: compressed-tensors from the config.1import torch
2from PIL import Image
3from transformers import (
4 Glm4vForConditionalGeneration,
5 Glm4vImageProcessor, Glm4vVideoProcessor, Glm4vProcessor,
6 AutoTokenizer,
7)
8
9MODEL = "Mitchins/GLM-4.6V-Flash-NVFP4-BF16Vision"
10
11model = Glm4vForConditionalGeneration.from_pretrained(
12 MODEL, dtype=torch.bfloat16, device_map="auto"
13)
14
15# Patch rope_scaling for transformers: config stores [8,12,12] (vllm-compatible),
16# but transformers doubles it internally so we must pre-double to [16,24,24].
17_rs = model.config.text_config.rope_scaling
18if _rs and _rs.get("mrope_section") == [8, 12, 12]:
19 _tf = [x * 2 for x in _rs["mrope_section"]]
20 for _mod in model.modules():
21 if hasattr(_mod, "rope_scaling") and isinstance(getattr(_mod, "rope_scaling", None), dict):
22 _mod.rope_scaling = {**_mod.rope_scaling, "mrope_section": _tf}
23
24tokenizer = AutoTokenizer.from_pretrained(MODEL)
25image_processor = Glm4vImageProcessor.from_pretrained(MODEL)
26video_processor = Glm4vVideoProcessor.from_pretrained(MODEL)
27processor = Glm4vProcessor(
28 image_processor=image_processor,
29 tokenizer=tokenizer,
30 video_processor=video_processor,
31 chat_template=tokenizer.chat_template,
32)
33
34image = Image.open("your_image.jpg").convert("RGB")
35messages = [{"role": "user", "content": [
36 {"type": "image"},
37 {"type": "text", "text": "Describe this image."},
38]}]
39text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
40inputs = processor(text=text, images=[image], return_tensors="pt")
41inputs = {k: v for k, v in inputs.items() if k != "token_type_ids"}
42inputs = {k: v.to(model.device) for k, v in inputs.items()}
43
44with torch.inference_mode():
45 out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
46
47print(processor.decode(out[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))FP8_BLOCK (data-free), NVFP4 uses SequentialPipeline in llmcompressor and requires a calibration dataloader. Pass a dataset to oneshot():1oneshot(
2 model=model, recipe=recipe, output_dir=SAVE_DIR,
3 dataset="wikitext",
4 dataset_config_name="wikitext-2-raw-v1",
5 splits="train",
6 num_calibration_samples=256,
7 max_seq_length=512,
8 text_column="text",
9 concatenate_data=True,
10)model.visual.* is excluded.oneshot() with NVFP4, the in-memory model has its Linear.weight replaced by packed representations. Standard model.generate() raises AttributeError: 'Linear' object has no attribute 'weight'. Reload from the saved directory before running inference:1del model; torch.cuda.empty_cache()
2model = Glm4vForConditionalGeneration.from_pretrained(SAVE_DIR, dtype=torch.bfloat16, device_map="auto")mrope_section doubling required for transformers inference (fix 2).python compress.py --fp4compress.py and verify.py are included in this repo.zai-org/GLM-4.6V-Flash, released under MIT. This quantized derivative inherits the same license.