badmadrad commited on
Commit
2d6140b
·
verified ·
1 Parent(s): 756cccf

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -35,6 +35,26 @@ MLX-optimized 3-bit quantization of [mistralai/Devstral-Small-2-24B-Instruct-251
35
  - **256K Context**: Supports up to 256K token context window
36
  - **Speculative Decoding Compatible**: Works with Mistral Tekken tokenizer draft models
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  ## Usage
39
 
40
  ```python
@@ -56,6 +76,7 @@ tools = [{"type": "function", "function": {"name": "read_file", "description": "
56
  messages = [{"role": "user", "content": "Read the file main.py"}]
57
  prompt = tokenizer.apply_chat_template(messages, tools=tools, tokenize=False, add_generation_prompt=True)
58
  response = generate(model, tokenizer, prompt=prompt, max_tokens=200)
 
59
  ```
60
 
61
  ### With Speculative Decoding
@@ -70,27 +91,20 @@ draft_model, _ = load("badmadrad/Mistral-Small-3.1-DRAFT-0.5B-MLX-4bit")
70
  # Draft model proposes tokens, main model verifies — faster generation
71
  ```
72
 
73
- ## Quantization Details
74
-
75
- Converted using `mlx_lm.convert`:
76
-
77
- ```bash
78
- mlx_lm.convert \
79
- --hf-path mistralai/Devstral-Small-2-24B-Instruct-2512 \
80
- --mlx-path ./devstral-v2-3bit \
81
- --quantize --q-bits 3 --q-group-size 64
82
- ```
83
-
84
- - **Method**: Affine quantization (3-bit with group size 64)
85
- - **Effective bits/weight**: ~3.5
86
- - **Memory savings**: ~75% vs BF16, ~20% vs 4-bit
87
-
88
  ## Hardware Requirements
89
 
90
  - Apple Silicon Mac (M1/M2/M3/M4)
91
- - Minimum 16 GB unified memory (recommended 32 GB+)
92
  - macOS 13.5+
93
 
 
 
 
 
 
 
 
 
94
  ## License
95
 
96
  Apache 2.0 (same as base model)
 
35
  - **256K Context**: Supports up to 256K token context window
36
  - **Speculative Decoding Compatible**: Works with Mistral Tekken tokenizer draft models
37
 
38
+ ## Quantization Method
39
+
40
+ This model was created using a **dequantize-requantize** workflow for optimal 3-bit quality:
41
+
42
+ ```bash
43
+ # Step 1: Dequantize the MLX 4-bit model back to BF16
44
+ mlx_lm.convert \
45
+ --hf-path mlx-community/mistralai_Devstral-Small-2-24B-Instruct-2512-MLX-4Bit \
46
+ --mlx-path ./devstral-v2-bf16 \
47
+ --dequantize --dtype bfloat16
48
+
49
+ # Step 2: Requantize from BF16 to 3-bit
50
+ mlx_lm.convert \
51
+ --hf-path ./devstral-v2-bf16 \
52
+ --mlx-path ./devstral-v2-3bit \
53
+ --quantize --q-bits 3 --q-group-size 64
54
+ ```
55
+
56
+ **Why this works**: Direct 3-bit quantization from the original HuggingFace BF16 weights produces degenerate output ("decay decay decay") due to weight distribution differences during the PyTorch-to-MLX conversion. Going through the MLX 4-bit model's dequantized BF16 preserves the weight structure that MLX inference requires.
57
+
58
  ## Usage
59
 
60
  ```python
 
76
  messages = [{"role": "user", "content": "Read the file main.py"}]
77
  prompt = tokenizer.apply_chat_template(messages, tools=tools, tokenize=False, add_generation_prompt=True)
78
  response = generate(model, tokenizer, prompt=prompt, max_tokens=200)
79
+ # Output: [TOOL_CALLS]read_file[ARGS]{"path": "main.py"}
80
  ```
81
 
82
  ### With Speculative Decoding
 
91
  # Draft model proposes tokens, main model verifies — faster generation
92
  ```
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  ## Hardware Requirements
95
 
96
  - Apple Silicon Mac (M1/M2/M3/M4)
97
+ - Minimum 16 GB unified memory
98
  - macOS 13.5+
99
 
100
+ ## Comparison
101
+
102
+ | Variant | Size | Quality | Tool Calling |
103
+ |---------|------|---------|-------------|
104
+ | BF16 (original) | ~48 GB | Best | Yes |
105
+ | 4-bit (mlx-community) | ~12 GB | Great | Yes |
106
+ | **3-bit (this model)** | **~9.6 GB** | **Good** | **Yes** |
107
+
108
  ## License
109
 
110
  Apache 2.0 (same as base model)
generation_config.json CHANGED
@@ -3,7 +3,5 @@
3
  "eos_token_id": 2,
4
  "max_length": 262144,
5
  "pad_token_id": 11,
6
- "do_sample": true,
7
- "temperature": 0.15,
8
  "transformers_version": "5.0.0.dev0"
9
  }
 
3
  "eos_token_id": 2,
4
  "max_length": 262144,
5
  "pad_token_id": 11,
 
 
6
  "transformers_version": "5.0.0.dev0"
7
  }
model-00001-of-00002.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7225d1c69f6106601fdab9ebc22c9f1f60d333f7aeae97a77746bd280dde1bfa
3
  size 5326582403
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:86938c62379f1c361c27356ee8aa4f1730032278f9acb2b8de86fa5f08397c85
3
  size 5326582403
model-00002-of-00002.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:674190296975560d2f0860d52e03d1c71b9df52c3e3baaf3def71d87d54d7ee5
3
  size 4987111828
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05c48505b7530ff654777143594bd67f1a4ca8455cf71f021ec96ee7010b35cf
3
  size 4987111828