NVIDIA-Nemotron-Nano-9B-v2-Japanese-4bit-mlx
English | 日本語 (Japanese follows below)
⚠️ LM Studio runtime v1.5.0 / v1.6.0 users: This model fails to load with
KeyError: '-'. Patch required. → See LM Studio section below.⚠️ LM Studio runtime v1.5.0 / v1.6.0 をお使いの方: このモデルは
KeyError: '-'エラーでロードできません。パッチが必要です。→ 下記 LM Studio セクションを参照。Note: This model requires manual fixes to
config.jsonandtokenizer_config.jsonafter conversion. See Conversion Notes / 変換時の注意事項 for details.
English
Overview
This model is a 4-bit quantized MLX format conversion of nvidia/NVIDIA-Nemotron-Nano-9B-v2-Japanese.
NVIDIA-Nemotron-Nano-9B-v2-Japanese is a hybrid Mamba-Transformer model (Nemotron-H architecture) optimized for the Japanese language. It achieves top-tier performance among sub-10B models on the Nejumi Leaderboard 4, Japan's most comprehensive LLM evaluation platform.
- Original Model: nvidia/NVIDIA-Nemotron-Nano-9B-v2-Japanese
- Architecture: Nemotron-H (Mamba-2 + Transformer hybrid)
- Quantization: 4-bit (group_size=64)
- Converted with: mlx-lm v0.31.0
Performance
Note on MLX inference speed: This model uses the Mamba-2 hybrid architecture (Nemotron-H), which relies on state space model (SSM) computations instead of standard attention. On Apple Silicon via MLX, SSM kernels are not yet as optimized as attention-based operations, resulting in slower token generation than comparably-sized Transformer models. NVIDIA's reported speed figures are CUDA-specific and should not be expected on MLX. See the fp16 version for details.
Tested on Apple MacBook Pro M4 Max (128GB):
| Metric | Value |
|---|---|
| Peak Memory | 5.2 GB |
| Prompt Processing | ~143 tokens/sec |
| Token Generation | ~79 tokens/sec |
Quality Evaluation
Disclaimer: Preliminary evaluation by the model converter. Not an official benchmark. See the fp16 version for full methodology and comparative results.
Evaluated using lm-evaluation-harness v0.4.11 on MacBook Pro M4 Max (128GB).
| Benchmark | fp16 (baseline) | 4-bit | Degradation | Verdict |
|---|---|---|---|---|
| WikiText-2 (word perplexity ↓) | 10.11 | 10.82 | +0.71 (+7.0%) | ✅ Pass |
| JCommonsenseQA (accuracy ↑) | 79.6% | 75.4% | −4.2pt | ⚠️ Warn |
Note: 4-bit passes the English perplexity threshold but shows a measurable drop in Japanese commonsense reasoning accuracy (−4.2 percentage points). For tasks requiring precise Japanese output, the 8-bit version is recommended.
Usage
mlx-lm (CLI)
pip install -U mlx-lm
mlx_lm.chat \
--model tocchitocchi/NVIDIA-Nemotron-Nano-9B-v2-Japanese-4bit-mlx \
--trust-remote-code
mlx-lm (Python)
from mlx_lm import load, generate
model, tokenizer = load(
"tocchitocchi/NVIDIA-Nemotron-Nano-9B-v2-Japanese-4bit-mlx",
tokenizer_config={"trust_remote_code": True}
)
messages = [
{"role": "system", "content": "/no_think"},
{"role": "user", "content": "日本の首都はどこですか?"}
]
prompt = tokenizer.apply_chat_template(
messages, add_generation_prompt=True
)
response = generate(model, tokenizer, prompt=prompt, max_tokens=512, verbose=True)
Reasoning Mode (Thinking)
This model uses reasoning traces (<think>...</think>) by default. The original NVIDIA model supports /think and /no_think system prompts to control reasoning, but on MLX (mlx-lm / LM Studio MLX backend), /no_think does not suppress reasoning traces. See the known limitation below.
⚠️ Known Limitation:
/no_thinkon MLX (mlx-lm / LM Studio MLX backend)
/no_thinkdoes not suppress reasoning traces when running via mlx-lm or LM Studio's MLX backend. The model generates<think>...</think>traces regardless of the/no_thinkdirective, and the output length is identical to/thinkmode. This is an upstream behavior — the original NVIDIA model'schat_templatealways inserts<think>, and/no_thinkis designed to be handled by the inference engine (e.g., vLLM on CUDA), not the prompt template.Impact on LM Studio (MLX backend): The MLX backend does not separate
<think>content from the response. Reasoning tokens consume themax_tokensbudget, which can cause empty responses ifmax_tokensis too low (e.g., 1500). Setmax_tokensto 4096 or higher as a workaround.GGUF format is not affected — LM Studio's llama.cpp backend correctly separates reasoning content from response content.
LM Studio
⚠️ LM Studio v1.5.0/v1.6.0 Known Issue: All Nemotron 9B series models fail to load with
KeyError: '-'in LM Studio v1.5.0. This is a LM Studio bug, not a model issue. v1.4.0 and earlier work without any patch. The Japanese MLX versions published by tocchitocchi have been verified working on v1.5.0 with the patches below.
Three files need to be patched under LM Studio's bundled Python packages. Apply once, then restart LM Studio.
Target directory:
~/.cache/lm-studio/extensions/backends/vendor/_amphibian/
app-mlx-generate-mac14-arm64@21/lib/python3.11/site-packages/
Patch 1 — transformers/models/nemotron_h/configuration_nemotron_h.py → _pattern_to_list:
Find:
pattern_mapping = {"M": "mamba", "E": "moe", "*": "attention"}
return [pattern_mapping[char] for char in pattern]
Replace with:
pattern_mapping = {"M": "mamba", "E": "moe", "*": "attention", "-": "mlp"}
return [pattern_mapping[char] for char in pattern if char in pattern_mapping]
Patch 2 — transformers/configuration_utils.py → ALLOWED_LAYER_TYPES:
Add "mlp" to the tuple:
ALLOWED_LAYER_TYPES = (
...
"moe", # for nemotron_h
"mlp", # for nemotron_h 9B which uses mlp layers
)
Patch 3 — transformers/models/nemotron_h/configuration_nemotron_h.py → valid_types (2 locations):
Find both occurrences of:
valid_types = {"mamba", "attention", "moe"}
Replace with:
valid_types = {"mamba", "attention", "moe", "mlp"}
See also: lmstudio-bug-tracker Issue #1774
Place the model files under:
~/.cache/lm-studio/models/<username>/NVIDIA-Nemotron-Nano-9B-v2-Japanese-4bit-mlx/
Conversion Notes
The model files in this repository are already fixed and ready to use. The following instructions are only for those who want to convert the original model themselves.
Important: When converting this model from the original safetensors using
mlx_lm.convert, two manual fixes are required after conversion. Without these fixes, the model will produce broken output.
1. Replace tokenizer_config.json
The conversion process generates a simplified tokenizer_config.json with "tokenizer_class": "TokenizersBackend", which is incorrect. Replace it with the original from NVIDIA:
cp <path-to-original-nvidia-model>/tokenizer_config.json <path-to-converted-mlx-model>/
2. Fix config.json
Three changes are needed in config.json:
| Item | Before (broken) | After (fixed) |
|---|---|---|
| dtype field | "dtype": "bfloat16" |
"torch_dtype": "bfloat16" |
| quantization mode | "mode": "affine" present |
Remove "mode": "affine" |
| time_step_limit | Missing | Add "time_step_limit": [0.0, Infinity] |
Fix script:
import json
with open('config.json') as f:
cfg = json.load(f)
cfg['torch_dtype'] = 'bfloat16'
if 'dtype' in cfg:
del cfg['dtype']
for key in ['quantization', 'quantization_config']:
if 'mode' in cfg.get(key, {}):
del cfg[key]['mode']
cfg['time_step_limit'] = [0.0, float('inf')]
with open('config.json', 'w') as f:
json.dump(cfg, f, indent=4)
Conversion Environment
| Package | Version |
|---|---|
| mlx | 0.31.0 |
| mlx-lm | 0.31.0 |
| transformers | 5.3.0 |
| Python | 3.13 |
| macOS | Apple Silicon (M4 Max) |
Other Quantizations
- 8-bit: tocchitocchi/NVIDIA-Nemotron-Nano-9B-v2-Japanese-8bit-mlx
- fp16: tocchitocchi/NVIDIA-Nemotron-Nano-9B-v2-Japanese-fp16-mlx
License
This model inherits the NVIDIA Nemotron Open Model License.
日本語
概要
nvidia/NVIDIA-Nemotron-Nano-9B-v2-JapaneseをMLX形式に変換し、4bit量子化したモデルです。
NVIDIA-Nemotron-Nano-9B-v2-Japaneseは、日本語に最適化されたMamba-Transformerハイブリッドモデル(Nemotron-Hアーキテクチャ)です。日本で最も包括的なLLM評価プラットフォームであるNejumi Leaderboard 4において、10B未満のモデルカテゴリでトップクラスの性能を達成しています。
- 元モデル: nvidia/NVIDIA-Nemotron-Nano-9B-v2-Japanese
- アーキテクチャ: Nemotron-H(Mamba-2 + Transformer ハイブリッド)
- 量子化: 4bit(group_size=64)
- 変換ツール: mlx-lm v0.31.0
パフォーマンス
MLXでの推論速度について: このモデルはMamba-2ハイブリッドアーキテクチャ(Nemotron-H)を採用しており、通常のAttentionではなくState Space Model(SSM)演算を使用しています。Apple SiliconのMLXではSSMカーネルの最適化がAttentionベースの演算ほど進んでおらず、同規模のTransformerモデルより生成速度が遅くなります。NVIDIAが公表している速度数値はCUDA環境での結果であり、MLX環境では期待できません。詳細はfp16版を参照してください。
Apple MacBook Pro M4 Max(128GB)での測定結果:
| 項目 | 値 |
|---|---|
| ピークメモリ | 5.2 GB |
| プロンプト処理速度 | 約143 tokens/秒 |
| トークン生成速度 | 約79 tokens/秒 |
品質評価
免責事項: モデル変換者による予備的・限定的な評価です。公式ベンチマークではありません。検証方法と全比較結果はfp16版を参照してください。
lm-evaluation-harness v0.4.11を使用し、MacBook Pro M4 Max(128GB)で評価。
| ベンチマーク | fp16(ベースライン) | 4bit | 劣化 | 判定 |
|---|---|---|---|---|
| WikiText-2(word perplexity ↓) | 10.11 | 10.82 | +0.71 (+7.0%) | ✅ Pass |
| JCommonsenseQA(正答率 ↑) | 79.6% | 75.4% | −4.2pt | ⚠️ Warn |
注意: 4bitは英語のperplexityは許容範囲内ですが、日本語常識推論の正答率が4.2ポイント低下します。日本語の正確さが重要な用途では8bit版を推奨します。
使用方法
mlx-lm(CLI)
pip install -U mlx-lm
mlx_lm.chat \
--model tocchitocchi/NVIDIA-Nemotron-Nano-9B-v2-Japanese-4bit-mlx \
--trust-remote-code
mlx-lm(Python)
from mlx_lm import load, generate
model, tokenizer = load(
"tocchitocchi/NVIDIA-Nemotron-Nano-9B-v2-Japanese-4bit-mlx",
tokenizer_config={"trust_remote_code": True}
)
messages = [
{"role": "system", "content": "/no_think"},
{"role": "user", "content": "日本の首都はどこですか?"}
]
prompt = tokenizer.apply_chat_template(
messages, add_generation_prompt=True
)
response = generate(model, tokenizer, prompt=prompt, max_tokens=512, verbose=True)
推論モード(Thinking)
このモデルはデフォルトで推論トレース(<think>...</think>)を生成します。NVIDIAオリジナルモデルは /think と /no_think システムプロンプトによる制御をサポートしていますが、MLX環境(mlx-lm / LM Studio MLXバックエンド)では /no_think は推論トレースを抑制しません。 下記の既知の制限を参照してください。
⚠️ 既知の制限: MLX環境での
/no_think(mlx-lm / LM Studio MLXバックエンド)mlx-lmまたはLM StudioのMLXバックエンド経由で実行した場合、
/no_thinkは推論トレースを抑制しません。/no_thinkを指定しても/thinkと同じ長さの<think>...</think>トレースが生成されます。これは上流の仕様であり、NVIDIAオリジナルモデルのchat_templateが常に<think>を挿入する設計になっているためです。/no_thinkの制御は推論エンジン(CUDA上のvLLM等)側で行われる想定であり、プロンプトテンプレートでは制御されません。LM Studio(MLXバックエンド)への影響: MLXバックエンドはレスポンス内の
<think>を分離しないため、推論トークンがmax_tokensの予算を消費します。max_tokensが小さい値(例: 1500)の場合、レスポンスが空になることがあります。回避策としてmax_tokensを 4096 以上に設定してください。GGUF形式ではこの問題は発生しません — LM Studioのllama.cppバックエンドは推論内容とレスポンス本文を正しく分離します。
LM Studio
⚠️ LM Studio v1.5.0/v1.6.0 既知の問題: Nemotron 9B系モデル全般が、LM Studio v1.5.0 で
KeyError: '-'エラーによりロードできません。モデルの問題ではなく、LM Studio 側のバグです。v1.4.0 以前はパッチなしで動作します。tocchitocchi が公開している日本語版 MLX モデルは、以下のパッチを適用することで v1.5.0 での動作を確認済みです。
3つのファイルにパッチを適用する必要があります。 1回実行すれば完了です。パッチ適用後、LM Studio を再起動してください。
対象ディレクトリ:
~/.cache/lm-studio/extensions/backends/vendor/_amphibian/
app-mlx-generate-mac14-arm64@21/lib/python3.11/site-packages/
パッチ 1 — transformers/models/nemotron_h/configuration_nemotron_h.py → _pattern_to_list:
以下を見つけて:
pattern_mapping = {"M": "mamba", "E": "moe", "*": "attention"}
return [pattern_mapping[char] for char in pattern]
次のように変更:
pattern_mapping = {"M": "mamba", "E": "moe", "*": "attention", "-": "mlp"}
return [pattern_mapping[char] for char in pattern if char in pattern_mapping]
パッチ 2 — transformers/configuration_utils.py → ALLOWED_LAYER_TYPES:
タプルに "mlp" を追加:
ALLOWED_LAYER_TYPES = (
...
"moe", # for nemotron_h
"mlp", # for nemotron_h 9B which uses mlp layers
)
パッチ 3 — transformers/models/nemotron_h/configuration_nemotron_h.py → valid_types(2箇所):
以下の記述を2箇所とも:
valid_types = {"mamba", "attention", "moe"}
次のように変更:
valid_types = {"mamba", "attention", "moe", "mlp"}
参考: lmstudio-bug-tracker Issue #1774
以下のディレクトリにモデルファイルを配置してください:
~/.cache/lm-studio/models/<ユーザー名>/NVIDIA-Nemotron-Nano-9B-v2-Japanese-4bit-mlx/
変換時の注意事項
本リポジトリのモデルファイルは修正済みで、そのまま使用できます。 以下の手順は、元のモデルを自分で変換する場合にのみ必要です。
重要:
mlx_lm.convertで元のsafetensorsモデルから変換した場合、変換後に2つのファイルの手動修正が必須です。修正しないとモデルが正常に動作しません。
1. tokenizer_config.json の置き換え
変換時に生成されるtokenizer_config.jsonは簡略化されており、"tokenizer_class": "TokenizersBackend"という不正な値が設定されます。元のNVIDIA公式モデルのファイルで上書きしてください:
cp <元のNVIDIAモデルのパス>/tokenizer_config.json <変換後のMLXモデルのパス>/
2. config.json の修正
config.jsonに3箇所の修正が必要です:
| 項目 | 修正前(不正) | 修正後(正常) |
|---|---|---|
| dtypeフィールド | "dtype": "bfloat16" |
"torch_dtype": "bfloat16" |
| quantization mode | "mode": "affine" あり |
"mode": "affine" を削除 |
| time_step_limit | なし | "time_step_limit": [0.0, Infinity] を追加 |
修正スクリプト:
import json
with open('config.json') as f:
cfg = json.load(f)
cfg['torch_dtype'] = 'bfloat16'
if 'dtype' in cfg:
del cfg['dtype']
for key in ['quantization', 'quantization_config']:
if 'mode' in cfg.get(key, {}):
del cfg[key]['mode']
cfg['time_step_limit'] = [0.0, float('inf')]
with open('config.json', 'w') as f:
json.dump(cfg, f, indent=4)
変換環境
| パッケージ | バージョン |
|---|---|
| mlx | 0.31.0 |
| mlx-lm | 0.31.0 |
| transformers | 5.3.0 |
| Python | 3.13 |
| macOS | Apple Silicon(M4 Max) |
他の量子化バージョン
- 8bit版: tocchitocchi/NVIDIA-Nemotron-Nano-9B-v2-Japanese-8bit-mlx
- fp16版: tocchitocchi/NVIDIA-Nemotron-Nano-9B-v2-Japanese-fp16-mlx
ライセンス
本モデルはNVIDIA Nemotron Open Model Licenseに基づいて提供されます。
- Downloads last month
- 473
4-bit