Views
No views yet
| Property | Value |
|---|---|
| Method | SINQ (Sinkhorn-Normalized Quantization) |
| Bits | 4 |
| Group Size | 64 |
| Calibration | Calibration-free (sinq method) |
| Tiling Mode | 1D |
| Format | Safetensors (sharded) |
1hf-quantizer quantize \
2 --model-id mistralai/Devstral-Small-2-24B-Instruct-2512 \
3 --output-dir ./outputs/devstral-sinq-4bit \
4 --nbits 4 \
5 --group-size 64 \
6 --calibration sinq \
7 --quantized-by maxence-bouvier1# Install SINQ fork with Mistral3 support
2pip install git+https://github.com/MaxenceBouvier/SINQ.git@fix/mistral3-conditional-generation
3
4# Install dependencies
5pip install transformers accelerate gemlite>=0.5.1.post1Note: This model requires the forked SINQ version with Mistral3ForConditionalGeneration fixes. The originalhuawei-csl/SINQwill not work.
1import torch
2from transformers import AutoProcessor
3from sinq.patch_model import AutoSINQHFModel
4
5model_id = "maxence-bouvier/Devstral-Small-2-24B-Instruct-SINQ-4bit"
6
7# Load quantized model (handles Hub download automatically)
8model = AutoSINQHFModel.from_quantized_safetensors(
9 model_id,
10 compute_dtype=torch.float16,
11 device="cuda",
12)
13
14# Load processor (handles tokenization and chat templates)
15processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)1def _build_unicode_to_bytes_map() -> dict[str, int]:
2 """Build inverse of GPT-2's bytes_to_unicode mapping."""
3 bs = (
4 list(range(ord("!"), ord("~") + 1))
5 + list(range(ord("¡"), ord("¬") + 1))
6 + list(range(ord("®"), ord("ÿ") + 1))
7 )
8 cs = bs[:]
9 n = 0
10 for b in range(256):
11 if b not in bs:
12 bs.append(b)
13 cs.append(256 + n)
14 n += 1
15 return {chr(c): b for b, c in zip(bs, cs)}
16
17_UNICODE_TO_BYTE = _build_unicode_to_bytes_map()
18
19def fix_byte_encoding(text: str) -> str:
20 """Fix byte-level BPE encoding for proper emoji/unicode display.
21
22 Example: "ð٤Ĺ" -> "🤗"
23 """
24 try:
25 byte_values = bytes([_UNICODE_TO_BYTE.get(c, ord(c)) for c in text])
26 return byte_values.decode("utf-8")
27 except (UnicodeDecodeError, KeyError, ValueError):
28 return text
29
30messages = [
31 {"role": "user", "content": "Write a Python function to check if a number is prime."}
32]
33
34text = processor.apply_chat_template(
35 messages,
36 tokenize=False,
37 add_generation_prompt=True
38)
39inputs = processor(text=text, return_tensors="pt").to("cuda")
40
41with torch.no_grad():
42 outputs = model.generate(
43 **inputs,
44 max_new_tokens=512,
45 do_sample=True,
46 temperature=0.7,
47 pad_token_id=processor.tokenizer.eos_token_id,
48 )
49
50response = processor.decode(outputs[0], skip_special_tokens=True)
51response = fix_byte_encoding(response) # Fix emoji/unicode display
52print(response)Note: Thefix_byte_encodinghelper is needed because Mistral uses byte-level BPE tokenization (GPT-2 style). UTF-8 bytes are encoded as individual Unicode characters (e.g., 🤗 becomesð٤Ĺ). This function reverses that mapping for proper display.
1# Minimal test to verify the model works
2messages = [{"role": "user", "content": "Say hello"}]
3text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
4inputs = processor(text=text, return_tensors="pt").to("cuda")
5
6with torch.no_grad():
7 out = model.generate(**inputs, max_new_tokens=50, do_sample=False,
8 pad_token_id=processor.tokenizer.eos_token_id)
9response = fix_byte_encoding(processor.decode(out[0], skip_special_tokens=True))
10print(response)| Configuration | Estimated VRAM |
|---|---|
| Inference (4-bit) | ~14 GB |
| + 16k Context | ~19 GB |