Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions python/freetoken/models/deepseek_v4/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,28 @@ def nope_head_dim(self) -> int:


def _config_path(model_path: str) -> str:
"""Locate the authors' ModelArgs JSON inside the checkpoint directory."""
candidates = [
os.path.join(model_path, "inference", "config.json"),
os.path.join(model_path, "model_args.json"),
]
for path in candidates:
if os.path.exists(path):
return path
"""Locate the authors' ModelArgs JSON inside the checkpoint directory.

``model_path`` is either a local directory or a Hugging Face repo id (e.g. when
serving straight from ``--model deepseek-ai/DeepSeek-V4-Flash-0731``, unresolved
to a local snapshot dir). For the repo-id case, resolve each candidate filename
through the HF cache/hub the same way ``utils.hf`` does for ``config.json``.
"""
filenames = [os.path.join("inference", "config.json"), "model_args.json"]
if os.path.isdir(model_path):
for filename in filenames:
path = os.path.join(model_path, filename)
if os.path.exists(path):
return path
else:
from huggingface_hub import hf_hub_download
from huggingface_hub.utils import EntryNotFoundError

for filename in filenames:
try:
return hf_hub_download(repo_id=model_path, filename=filename)
except EntryNotFoundError:
continue
raise FileNotFoundError(
f"No DeepSeek-V4 ModelArgs JSON found under {model_path} "
f"(looked for inference/config.json)"
Expand Down
4 changes: 3 additions & 1 deletion python/freetoken/models/deepseek_v4/weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from tqdm import tqdm

from freetoken.models.loader import drop_page_cache
from freetoken.utils import download_hf_weight

from .args import DeepseekV4Args, load_args

Expand Down Expand Up @@ -93,6 +94,7 @@ def iter_weights(
if not include_non_moe:
return

model_path = download_hf_weight(model_path)
args = load_args(model_path, max_batch_size=1)
reader = _ShardReader(model_path, _weight_map(model_path), device)

Expand Down Expand Up @@ -189,7 +191,7 @@ def load_dsfp4_expert_sources(
"""
from freetoken.moe.host_banks import LayerCompletionTracker, PinPipeline, alloc_layer_banks

folder = model_path
folder = download_hf_weight(model_path)
weight_map = _weight_map(folder)
L, E = args.n_layers, args.n_routed_experts
H, I = args.dim, args.moe_inter_dim
Expand Down