Views
No views yet

Kimi-Linear-48B model using the SINQ (Sinkhorn-Normalized Quantization) method presented in SINQ: Sinkhorn-Normalized Quantization for Calibration-Free Low-Precision LLM Weights.Kimi-Linear-48B-A3B-Instruct-4bit-SINQKimi-Linear-48Bsinq1import torch
2from transformers import AutoTokenizer
3from sinq.patch_model import AutoSINQHFModel
4
5model_name = "huawei-csl/Kimi-Linear-48B-A3B-Instruct-4bit-SINQ"
6tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
7device = "cuda:0"
8
9sinq_model = AutoSINQHFModel.from_quantized_safetensors(
10 model_name,
11 device=device,
12 attn_implementation = "kernels-community/flash-attn2",
13 compute_dtype=torch.bfloat16,
14 trust_remote_code=True
15)
16
17# Test the quantized model
18messages = [
19 {"role": "system", "content": "You are a helpful assistant provided by Moonshot-AI."},
20 {"role": "user", "content": "Is 7 a prime?"}
21]
22
23chat_prompt = tokenizer.apply_chat_template(
24 messages,
25 add_generation_prompt=True, # ask it to end with assistant turn
26 # no return_tensors here; this returns a string in your version
27)
28inputs = tokenizer(
29 chat_prompt,
30 return_tensors="pt"
31)
32
33inputs = {k: v.to(sinq_model.device) for k, v in inputs.items()}
34if tokenizer.pad_token_id is None:
35 tokenizer.pad_token = tokenizer.eos_token
36
37with torch.no_grad():
38 generated_ids = sinq_model.generate(
39 input_ids=inputs["input_ids"],
40 attention_mask=inputs.get("attention_mask", None),
41 max_new_tokens=200
42 )
43
44new_tokens = generated_ids[0, inputs["input_ids"].shape[-1]:]
45response = tokenizer.decode(new_tokens, skip_special_tokens=True)
46print(response)
471import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from sinq.patch_model import AutoSINQHFModel
4from sinq.sinqlinear import BaseQuantizeConfig
5
6# Load base model
7model_name = "moonshotai/Kimi-Linear-48B-A3B-Instruct"
8tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
9model = AutoModelForCausalLM.from_pretrained(
10 model_name,
11 torch_dtype="auto",
12 trust_remote_code=True,
13 attn_implementation = "kernels-community/flash-attn2",
14)
15
16# Apply 4-bit SINQ quantization
17quant_cfg = BaseQuantizeConfig(
18 nbits=4, # quantization bit-width
19 group_size=64, # group size
20 tiling_mode="1D", # tiling strategy
21 method="sinq" # quantization method ("asinq" for the calibrated version)
22)
23
24sinq_model = AutoSINQHFModel.quantize_model(
25 model,
26 tokenizer=tokenizer,
27 quant_config=quant_cfg,
28 compute_dtype=torch.bfloat16,
29 device="cuda:0"
30)1@misc{muller2025sinq,
2 title={SINQ: Sinkhorn-Normalized Quantization for Calibration-Free Low-Precision LLM Weights},
3 author={Lorenz K. Muller and Philippe Bich and Jiawei Zhuang and Ahmet Celik and Luca Benfenati and Lukas Cavigelli},
4 year={2025},
5 eprint={2509.22944},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={http://arxiv.org/abs/2509.22944}
9}