Views
No views yet
| Property | Value |
|---|---|
| Base Model | mistralai/Devstral-2-123B-Instruct-2512 |
| Quantization | NVFP4 (4-bit floating point) |
| Format | TensorRT-LLM checkpoint |
| Size | ~120GB (from 240GB FP8) |
| Quantization Time | 4.76 minutes on B300 |
| Producer | nvidia-modelopt 0.27.1 |
1{
2 "architecture": "LlamaForCausalLM",
3 "dtype": "bfloat16",
4 "num_hidden_layers": 88,
5 "num_attention_heads": 96,
6 "num_key_value_heads": 8,
7 "hidden_size": 12288,
8 "vocab_size": 131072,
9 "quantization": {
10 "quant_algo": "NVFP4",
11 "group_size": 128,
12 "has_zero_point": false,
13 "pre_quant_scale": true
14 }
15}1# Use NVIDIA PyTorch container
2docker pull nvcr.io/nvidia/pytorch:25.05-py3
3
4# Install dependencies (git transformers required for ministral3)
5pip install tokenizers git+https://github.com/huggingface/transformers.git accelerate datasets1#!/usr/bin/env python3
2import torch, time, os
3
4# CRITICAL PATCH 1: Add Conv1D to transformers
5import transformers.modeling_utils as mu
6if not hasattr(mu, "Conv1D"):
7 import torch.nn as nn
8 class Conv1D(nn.Module):
9 def __init__(self, nf, nx):
10 super().__init__()
11 self.nf = nf
12 w = torch.empty(nx, nf)
13 nn.init.normal_(w, std=0.02)
14 self.weight = nn.Parameter(w)
15 self.bias = nn.Parameter(torch.zeros(nf))
16 def forward(self, x):
17 size_out = x.size()[:-1] + (self.nf,)
18 x = torch.addmm(self.bias, x.view(-1, x.size(-1)), self.weight)
19 return x.view(size_out)
20 mu.Conv1D = Conv1D
21
22# CRITICAL PATCH 2: Disable attention auto-registration
23import modelopt.torch.quantization.plugins.huggingface as hf_plugin
24hf_plugin.register_hf_attentions_on_the_fly = lambda model: None
25
26# Load model
27from transformers import AutoModelForCausalLM, AutoTokenizer
28model = AutoModelForCausalLM.from_pretrained(
29 "mistralai/Devstral-2-123B-Instruct-2512",
30 torch_dtype="auto",
31 device_map="auto",
32 trust_remote_code=True,
33 attn_implementation="flash_attention_2"
34)
35
36# Prepare calibration
37tokenizer = AutoTokenizer.from_pretrained(
38 "mistralai/Devstral-2-123B-Instruct-2512",
39 trust_remote_code=True
40)
41from datasets import load_dataset
42dataset = load_dataset("cnn_dailymail", "3.0.0", split="train", streaming=True)
43calib_texts = [item["article"][:6000] for i, item in enumerate(dataset) if i < 128]
44calib_enc = tokenizer(
45 calib_texts, padding=True, truncation=True, max_length=2048, return_tensors="pt"
46)
47
48# Quantize
49import modelopt.torch.quantization as mtq
50def calibrate_loop(model):
51 device = next(model.parameters()).device
52 for i in range(len(calib_texts)):
53 ids = calib_enc.input_ids[i:i+1].to(device)
54 mask = calib_enc.attention_mask[i:i+1].to(device)
55 with torch.no_grad():
56 model(input_ids=ids, attention_mask=mask)
57
58model = mtq.quantize(model, mtq.NVFP4_DEFAULT_CFG.copy(), forward_loop=calibrate_loop)
59
60# Export
61from modelopt.torch.export import export_tensorrt_llm_checkpoint
62export_tensorrt_llm_checkpoint(
63 model,
64 decoder_type="llama",
65 dtype=torch.bfloat16,
66 export_dir="./devstral-123b-nvfp4",
67 inference_tensor_parallel=1,
68 inference_pipeline_parallel=1
69)pip install git+https://github.com/huggingface/transformers.git