From 06e4ec600150a8936147e0919b52c917f278da1a Mon Sep 17 00:00:00 2001 From: Ahmed Hassanin Date: Sun, 6 Sep 2026 23:34:53 -0400 Subject: [PATCH] fix(models): serve qwen4_exp FTW checkpoints with PLE streamed from source The FTW converter stores dense weights and expert banks only; the PLE n-gram table is skipped by iter_weights and no safetensors index is copied. Resolving PLE rows from an FTW dir therefore found zero shards. Fall back to the conversion source recorded in freetoken_weight.json, which covers both the disk and pinned PLE paths. --- python/freetoken/models/qwen4_exp/weight.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python/freetoken/models/qwen4_exp/weight.py b/python/freetoken/models/qwen4_exp/weight.py index f8d2a7494..41816065d 100644 --- a/python/freetoken/models/qwen4_exp/weight.py +++ b/python/freetoken/models/qwen4_exp/weight.py @@ -215,6 +215,21 @@ def _ple_table_files(folder: str) -> list[str]: """Shards holding a piece of the n-gram table, from the index when there is one.""" index = os.path.join(folder, "model.safetensors.index.json") if not os.path.exists(index): + # FTW checkpoints carry no safetensors index -- and the converter never + # writes the PLE table (iter_weights skips ngram_embedding.*). Stream it + # from the conversion source recorded in the FTW index instead. + from freetoken.checkpoint.ftw import INDEX_NAME, is_ftw_checkpoint + + if is_ftw_checkpoint(folder): + with open(os.path.join(folder, INDEX_NAME), encoding="utf-8") as fh: + src = json.load(fh).get("source_model_path") + if src and os.path.isdir(src): + return _ple_table_files(src) + raise ValueError( + f"FTW checkpoint {folder} holds no PLE n-gram table and its " + f"conversion source {src!r} is missing; re-convert with the " + "source present or serve the safetensors checkpoint directly" + ) return sorted(iter_weight_files(folder)) with open(index, encoding="utf-8") as fh: weight_map = json.load(fh)["weight_map"]