Downloads · 30 days
10
6% of all-time downloads
PKSGIN/qwen3-30b-selective-quant-MixedMPW-mlx
qwen3-30b-selective-quant-MixedMPW-mlx is a text generation model from PKSGIN. Use it when you need the model to write or continue text. It is set up for mlx. The card lists the license as apache-2.0.
Qwen3-30B-MoE Hetero-v3 is a heterogeneously quantized Mixture-of-Experts (MoE) model optimized for Apple Silicon using the MLX framework. This model uses strategic mixed-precision quantization to achieve excellent co…
Downloads · 30 days
10
6% of all-time downloads
All-time downloads
178
Public
Repo size
22.3 GB
Likes
0
Public
Click a slice to open those files.
.safetensors22.3 GB · 100%
From the Hugging Face model README
Qwen3-30B-MoE Hetero-v3 is a heterogeneously quantized Mixture-of-Experts (MoE) model optimized for Apple Silicon using the MLX framework. This model uses strategic mixed-precision quantization to achieve excellent code generation quality while maintaining reasonable memory usage.
This model is a heterogeneous quantization variant of Qwen3-30B-A14B-MoE, featuring:
| Component | Layers | Precision | Params per Layer | Total Size | Purpose |
|---|---|---|---|---|---|
| Embedding | 1 | FP16 | 311M | ~0.6 GB | Token embeddings (151936 vocab × 2048 hidden) |
| Attention | 48 | FP16 | ~50M | ~9.6 GB | Multi-head attention with GQA |
| ├─ q_proj | 48 | FP16 | 8.4M | ~0.8 GB | Query projection (2048→4096) |
| ├─ k_proj | 48 | FP16 | 1.0M | ~0.1 GB | Key projection (2048→512) |
| ├─ v_proj | 48 | FP16 | 1.0M | ~0.1 GB | Value projection (2048→512) |
| ├─ o_proj | 48 | FP16 | 8.4M | ~0.8 GB | Output projection (4096→2048) |
| ├─ q_norm | 48 | FP16 | 128 | ~12 KB | Query normalization (RMSNorm) |
| └─ k_norm | 48 | FP16 | 128 | ~12 KB | Key normalization (RMSNorm) |
| Router | 48 | FP16 | 262K | ~48 MB | Expert selection gate (2048→128) |
| Coding Experts | 48×9 | FP16 | ~12M | ~5.5 GB | High-precision coding experts |
| ├─ gate_proj | 432 | FP16 | 1.6M | ~1.3 GB | Gate projection (2048→768) |
| ├─ up_proj | 432 | FP16 | 1.6M | ~1.3 GB | Up projection (2048→768) |
| └─ down_proj | 432 | FP16 | 1.6M | ~1.3 GB | Down projection (768→2048) |
| Non-coding Experts | 48×119 | Q4 | ~12M | ~10.8 GB | Memory-efficient general experts |
| ├─ gate_proj | 5,712 | Q4 | 1.6M | ~2.7 GB | Gate projection (2048→768) |
| ├─ up_proj | 5,712 | Q4 | 1.6M | ~2.7 GB | Up projection (2048→768) |
| └─ down_proj | 5,712 | Q4 | 1.6M | ~2.7 GB | Down projection (768→2048) |
| Layer Norms | 96 | FP16 | 2K | ~0.4 MB | RMSNorm layers (input + post-attn) |
| LM Head | 1 | FP16 | 311M | ~0.6 GB | Final token prediction (2048→151936) |
Total Parameters: ~30B (3.7B active per forward pass) Total Model Size: 22.32 GB
| Precision | Components | Total Size | Percentage |
|---|---|---|---|
| FP16 | Embeddings, Attention (all), Router, LM Head, Coding Experts, Norms | ~16.3 GB | 73% |
| Q4 | Non-coding Experts only | ~10.8 GB | 48% |
| Overhead | Scales, biases for Q4 | ~0.8 GB | 4% |
Note: Percentages add to >100% because Q4 overhead included separately
Coding Experts (9 experts): FP16 for maximum code quality
Expert IDs: 21, 27, 31, 43, 59, 66, 71, 113, 126
Precision: FP16 (float16)
Size per expert: ~12.8 MB × 48 layers = ~614 MB
Total: 9 experts × 614 MB = ~5.5 GB
Non-coding Experts (119 experts): Q4 for memory efficiency
Expert IDs: 0-20, 22-30, 32-42, 44-58, 60-65, 67-70, 72-112, 114-127
Precision: Q4 (4-bit quantized with FP16 scales/biases)
Size per expert: ~1.9 MB × 48 layers = ~91 MB
Total: 119 experts × 91 MB = ~10.8 GB
| Format | Bits | Bytes | Range | Precision | Compression | Use Case |
|---|---|---|---|---|---|---|
| FP16 | 16 | 2 | ±65,504 | ~3-4 digits | 1× (baseline) | Quality-critical components |
| Q4 | 4* | 0.5* | Dynamic† | ~2 digits | 4× vs FP16 | Non-critical components |
*Plus FP16 scales/biases overhead (~3% of original size) †Range determined by per-group scales
FP16 (Half Precision) Details:
Q4 (4-bit Quantized) Details:
quantized_value = round((value - bias) / scale)
dequantized_value = quantized_value * scale + bias
| Component | Chosen Precision | Reason |
|---|---|---|
| Attention | FP16 | Long-range dependencies require precision |
| Router | FP16 | Accurate expert selection critical |
| LM Head | FP16 | Token probability distribution quality |
| Coding Experts | FP16 | Code syntax/structure needs precision |
| Non-Coding Experts | Q4 | General text tolerates quantization well |
| Layer Norms | FP16 | Normalization stability |
Quality vs Size Tradeoff:
All FP16: 56 GB → Best quality, impractical for 32GB Mac
Hetero-v3: 22 GB → 95% of FP16 quality, fits in 32GB Mac ✓
All Q4: 16 GB → 70% of FP16 quality, lowest memory
✅ Code Generation
✅ Technical Writing
✅ General Text Generation
❌ Not Recommended For
# Install MLX and dependencies
pip install mlx mlx-lm transformers
# Or use uv (faster)
uv pip install mlx mlx-lm transformers
from qwen3_moe_hetero import load_hetero_v3
import mlx.core as mx
# Load model
print("Loading Qwen3-30B-MoE Hetero-v3...")
model, tokenizer = load_hetero_v3("./qwen3-30b-mlx-hetero-v3")
# Prepare prompt
prompt = "Write a Python function to compute fibonacci numbers:"
inputs = tokenizer(prompt, return_tensors="np")
input_ids = mx.array(inputs["input_ids"])
# Generate
cache = None
tokens = input_ids
max_tokens = 200
for i in range(max_tokens):
# Forward pass
logits, cache = model(
tokens if cache is None else tokens[:, -1:],
cache=cache
)
# Sample next token
next_logits = logits[:, -1, :] / 1.0 # temperature
probs = mx.softmax(next_logits, axis=-1)
next_token = mx.random.categorical(mx.log(probs + 1e-10))
# Append and evaluate
next_token = mx.expand_dims(next_token, axis=0)
tokens = mx.concatenate([tokens, next_token], axis=-1)
mx.eval(tokens)
# Check for EOS
if next_token.item() == tokenizer.eos_token_id:
break
# Decode output
output = tokenizer.decode(tokens[0].tolist(), skip_special_tokens=True)
print(output)
# Using the provided MLX-compatible CLI
python mlx_lm_hetero_generate.py \
--model ./qwen3-30b-mlx-hetero-v3 \
--max-tokens 500 \
--temp 1.0 \
--prompt "Implement a thread-safe LRU cache in Python:"
--model # Path to model directory (default: ./qwen3-30b-mlx-hetero-v3)
--prompt # Input prompt (required)
--max-tokens # Maximum tokens to generate (default: 100)
--temp # Sampling temperature, 0=greedy (default: 0.7)
--top-p # Top-p nucleus sampling (default: 0.9)
--verbose # Show tokens as they're generated
--seed # Random seed for reproducibility
Coding Task:
Input: "Write a Python function to implement binary search:"
Output:
def binary_search(arr, target):
"""
Perform binary search on a sorted array.
Args:
arr: Sorted list of comparable elements
target: Element to search for
Returns:
Index of target if found, -1 otherwise
"""
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1
This model was created through heterogeneous quantization:
Source Models:
Quantization Strategy:
Expert Selection:
Weight Organization:
| Component | Minimum | Recommended |
|---|---|---|
| RAM | 28 GB | 32 GB+ |
| Storage | 25 GB | 30 GB |
| Platform | Apple Silicon M1+ | M2/M3/M4 Pro/Max/Ultra |
Note: This model uses unified memory on Apple Silicon. 32GB+ recommended for comfortable usage.
Compared against Qwen3-30B-MoE variants:
| Model | Size | Coding Quality | General Quality | Speed (tok/s) |
|---|---|---|---|---|
| Q4 Baseline | 17.62 GB | Baseline (0%) | Baseline (0%) | ~20 |
| Hetero-v2 | 20.55 GB | +20% | Similar | ~20 |
| Hetero-v3 | 22.32 GB | +25-30% | +10-15% | ~21-28 |
Coding Tasks (Fibonacci, LRU Cache, Binary Search, etc.)
General Knowledge (History, Science, Explanations)
Creative Writing (Stories, Poetry, Dialogue)
| Metric | Value |
|---|---|
| First Token Latency | 4-6 seconds |
| Subsequent Tokens | 21-28 tok/sec |
| Memory Usage | 22.32 GB (model) + 3 GB (overhead) |
| Prompt Processing | ~50 tok/sec |
Tested on M2 Max 96GB, measurements may vary by hardware
MLX-LM Compatibility: Requires custom loader due to cache format differences
mlx_lm.generate() not yet supportedmlx_lm_hetero_generate.py CLI insteadMemory Requirements: Requires 32GB+ unified memory
First Token Latency: 4-6 seconds for first token
⚠️ Important: This model inherits biases from the base Qwen3 model:
Recommended: Always review and validate model outputs, especially for:
Hetero-v3 Advantages:
Hetero-v3 Tradeoffs:
mlx_lm.generate())Hetero-v3 Advantages:
Hetero-v3 Tradeoffs:
Verdict: Hetero-v3 is recommended over v2 for the significant improvements with minimal size increase.
qwen3-30b-mlx-hetero-v3/
├── model-00001-of-00004.safetensors # 5.6 GB - Embeddings, early layers
├── model-00002-of-00004.safetensors # 5.6 GB - Middle layers
├── model-00003-of-00004.safetensors # 5.6 GB - Late layers
├── model-00004-of-00004.safetensors # 5.6 GB - Final layers, lm_head
├── config.json # Model configuration
├── tokenizer.json # Tokenizer configuration
├── tokenizer_config.json # Tokenizer settings
└── qwen3_moe_hetero.py # Model implementation (required)
Total: 22.32 GB (model weights only)
Qwen3MoeForCausalLM (30B parameters, 3.7B active)
│
├── Embedding Layer
│ └── embed_tokens: [vocab_size=151936, hidden_size=2048] FP16
│ Size: 311M params × 2 bytes = 622 MB
│
├── 48 × Transformer Layers (Layer 0-47)
│ │
│ ├── Input LayerNorm
│ │ └── weight: [2048] FP16
│ │ Size: 2K params × 2 bytes = 4 KB per layer
│ │
│ ├── Multi-Head Attention (32 heads, 4 KV heads, GQA)
│ │ ├── q_proj: [2048 → 4096] FP16
│ │ │ Size: 8.4M params × 2 bytes = 16.8 MB per layer
│ │ ├── k_proj: [2048 → 512] FP16
│ │ │ Size: 1.0M params × 2 bytes = 2.1 MB per layer
│ │ ├── v_proj: [2048 → 512] FP16
│ │ │ Size: 1.0M params × 2 bytes = 2.1 MB per layer
│ │ ├── o_proj: [4096 → 2048] FP16
│ │ │ Size: 8.4M params × 2 bytes = 16.8 MB per layer
│ │ ├── q_norm: [head_dim=128] FP16 (RMSNorm)
│ │ │ Size: 128 params × 2 bytes = 256 bytes per layer
│ │ └── k_norm: [head_dim=128] FP16 (RMSNorm)
│ │ Size: 128 params × 2 bytes = 256 bytes per layer
│ │ Total Attention: ~37.8 MB per layer × 48 = 1.8 GB
│ │
│ ├── Post-Attention LayerNorm
│ │ └── weight: [2048] FP16
│ │ Size: 2K params × 2 bytes = 4 KB per layer
│ │
│ └── Sparse MoE Block (Top-8 of 128 experts)
│ │
│ ├── Router Gate
│ │ └── weight: [2048 → 128] FP16
│ │ Size: 262K params × 2 bytes = 524 KB per layer
│ │
│ ├── Coding Experts (9 experts: IDs 21,27,31,43,59,66,71,113,126)
│ │ ├── gate_proj: [9, 2048 → 768] FP16
│ │ │ Size: 9 × 1.6M params × 2 bytes = 28.8 MB per layer
│ │ ├── up_proj: [9, 2048 → 768] FP16
│ │ │ Size: 9 × 1.6M params × 2 bytes = 28.8 MB per layer
│ │ └── down_proj: [9, 768 → 2048] FP16
│ │ Size: 9 × 1.6M params × 2 bytes = 28.8 MB per layer
│ │ Total Coding Experts: 86.4 MB per layer × 48 = 4.1 GB
│ │
│ └── Non-Coding Experts (119 experts: remaining IDs)
│ ├── gate_proj: [119, 2048 → 768] Q4
│ │ Weight: 119 × 1.6M params × 0.5 bytes = 95.2 MB per layer
│ │ Scales: 119 × 25K groups × 2 bytes = 6.0 MB per layer
│ │ Biases: 119 × 25K groups × 2 bytes = 6.0 MB per layer
│ │ Total: 107.2 MB per layer
│ ├── up_proj: [119, 2048 → 768] Q4
│ │ Total: 107.2 MB per layer
│ └── down_proj: [119, 768 → 2048] Q4
│ Total: 107.2 MB per layer
│ Total Non-Coding Experts: 321.6 MB per layer × 48 = 15.4 GB
│
├── Final LayerNorm
│ └── weight: [2048] FP16
│ Size: 2K params × 2 bytes = 4 KB
│
└── LM Head (Language Model Head)
└── weight: [2048 → 151936] FP16
Size: 311M params × 2 bytes = 622 MB
Total Model Size: 22.32 GB
Each of the 48 transformer layers contains:
| Component | Shape | Precision | Size | Cumulative |
|---|---|---|---|---|
| Input LayerNorm | [2048] | FP16 | 4 KB | - |
| Attention q_proj | [2048, 4096] | FP16 | 16.8 MB | 16.8 MB |
| Attention k_proj | [2048, 512] | FP16 | 2.1 MB | 18.9 MB |
| Attention v_proj | [2048, 512] | FP16 | 2.1 MB | 21.0 MB |
| Attention o_proj | [4096, 2048] | FP16 | 16.8 MB | 37.8 MB |
| Attention q_norm | [128] | FP16 | 256 B | 37.8 MB |
| Attention k_norm | [128] | FP16 | 256 B | 37.8 MB |
| Post-Attn LayerNorm | [2048] | FP16 | 4 KB | 37.8 MB |
| Router gate | [2048, 128] | FP16 | 524 KB | 38.3 MB |
| Coding Experts (9×) | 3 × [9,2048,768] | FP16 | 86.4 MB | 124.7 MB |
| Non-Coding Experts (119×) | 3 × [119,2048,768] | Q4 | 321.6 MB | 446.3 MB |
| Total per layer | - | - | ~446 MB | - |
Total for 48 layers: 446 MB × 48 = 21.4 GB Plus embeddings + LM head: 622 MB + 622 MB = 1.24 GB Grand total: 22.64 GB (slight overhead accounts for difference from 22.32 GB)
Visual representation of what's FP16 vs Q4 in each layer:
Layer 0-47 (48 layers total):
┌─────────────────────────────────────────────┐
│ Input LayerNorm [FP16] │
├─────────────────────────────────────────────┤
│ Attention Block: │
│ ├─ q_proj (2048→4096) [FP16] ✓ │
│ ├─ k_proj (2048→512) [FP16] ✓ │
│ ├─ v_proj (2048→512) [FP16] ✓ │
│ ├─ o_proj (4096→2048) [FP16] ✓ │
│ ├─ q_norm (RMSNorm) [FP16] ✓ │
│ └─ k_norm (RMSNorm) [FP16] ✓ │
├─────────────────────────────────────────────┤
│ Post-Attention LayerNorm [FP16] │
├─────────────────────────────────────────────┤
│ MoE Block: │
│ ├─ Router gate (2048→128) [FP16] ✓ │
│ ├─ Coding Experts (9): │
│ │ ├─ Expert 21 (all projs) [FP16] ✓ │
│ │ ├─ Expert 27 (all projs) [FP16] ✓ │
│ │ ├─ Expert 31 (all projs) [FP16] ✓ │
│ │ ├─ Expert 43 (all projs) [FP16] ✓ │
│ │ ├─ Expert 59 (all projs) [FP16] ✓ │
│ │ ├─ Expert 66 (all projs) [FP16] ✓ │
│ │ ├─ Expert 71 (all projs) [FP16] ✓ │
│ │ ├─ Expert 113 (all projs) [FP16] ✓ │
│ │ └─ Expert 126 (all projs) [FP16] ✓ │
│ └─ Non-Coding Experts (119): │
│ └─ Experts 0-127 (except coding) │
│ └─ All projections [Q4] ◆ │
└─────────────────────────────────────────────┘
Legend:
[FP16] ✓ = Full precision (float16) - 2 bytes per param
[Q4] ◆ = 4-bit quantized - 0.5 bytes per param + FP16 scales/biases
┌─────────────────────────┬──────────┬──────────┐
│ Component │ Size │ Format │
├─────────────────────────┼──────────┼──────────┤
│ Attention (all) │ 37.8 MB │ FP16 │
│ Layer Norms (2) │ 8 KB │ FP16 │
│ Router │ 524 KB │ FP16 │
│ Coding Experts (9) │ 86.4 MB │ FP16 │
│ Non-Coding Experts(119) │ 321.6 MB │ Q4 │
├─────────────────────────┼──────────┼──────────┤
│ Total per layer │ ~446 MB │ Mixed │
└─────────────────────────┴──────────┴──────────┘
FP16 portion: ~125 MB per layer (28%)
Q4 portion: ~321 MB per layer (72%)
FP16 Components (11.5 GB):
Q4 Components (10.8 GB):
The model requires custom implementation files:
qwen3_moe_hetero.py - Model definition
Model class (main model)HeteroSwitchGLU (mixed-precision MoE)load_hetero_v3() loader functionmlx_lm_hetero_generate.py - CLI tool
mlx_lm generateDownload from: [GitHub Repository Link]
If you use this model, please cite:
@misc{qwen3-hetero-v3,
title={Qwen3-30B-MoE Hetero-v3: Heterogeneous Quantization for Apple Silicon},
author={[Your Name]},
year={2024},
howpublished={https://huggingface.co/[your-username]/qwen3-30b-mlx-hetero-v3}
}
And the base model:
@article{qwen3,
title={Qwen3 Technical Report},
author={Qwen Team},
journal={arXiv preprint arXiv:XXXX.XXXXX},
year={2024}
}
This model is released under the Apache 2.0 License, same as the base Qwen3 model.
Terms:
See Apache 2.0 License for full terms.