diff --git a/pyproject.toml b/pyproject.toml index a6ea333..1a41629 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "gen-worker" -version = "0.26.1" +version = "0.26.2" description = "A library used to build custom functions in Cozy Creator's serverless function platform." readme = "README.md" license = "MIT" diff --git a/src/gen_worker/models/download.py b/src/gen_worker/models/download.py index e5cc41a..6654dd4 100644 --- a/src/gen_worker/models/download.py +++ b/src/gen_worker/models/download.py @@ -788,8 +788,10 @@ def _civitai_select_files( ) -> list[dict[str, Any]]: """Downloadable weight files of a model version, primary first. - Safetensors files win when present (unchanged behavior). GGUF-only - versions (th#611: klein/qwen fine-tunes published only as quants) + Safetensors files win when present. Civitai may publish alternative + precisions under the same filename; keep the primary/first alternative + once so a later variant cannot overwrite it on disk. GGUF-only versions + (th#611: klein/qwen fine-tunes published only as quants) select exactly ONE gguf — civitai reuses a single filename across quantType variants, so downloading several would collide on disk: ``gguf_quant`` picks it explicitly, else the preference order applies. @@ -809,7 +811,10 @@ def _civitai_select_files( gg.append(entry) if st: st.sort(key=lambda f: (0 if f["primary"] else 1, f["id"], f["name"])) - return st + unique: dict[str, dict[str, Any]] = {} + for f in st: + unique.setdefault(f["name"], f) + return list(unique.values()) if not gg: return [] gg.sort(key=lambda f: (f["id"], f["name"])) diff --git a/tests/convert/test_civitai_gguf_select.py b/tests/convert/test_civitai_gguf_select.py index ab4265c..0612b69 100644 --- a/tests/convert/test_civitai_gguf_select.py +++ b/tests/convert/test_civitai_gguf_select.py @@ -35,6 +35,18 @@ def test_safetensors_win_over_gguf(): assert [f["name"] for f in files] == ["model.safetensors"] +def test_safetensors_same_name_keeps_primary_without_dropping_distinct_files(): + files = _civitai_select_files({"files": [ + _f("model.safetensors", id=2), + _f("text_encoder.safetensors", id=3), + _f("model.safetensors", id=1, primary=True), + ]}) + assert [(f["id"], f["name"]) for f in files] == [ + (1, "model.safetensors"), + (3, "text_encoder.safetensors"), + ] + + def test_gguf_only_picks_one_by_preference(): files = _civitai_select_files({"files": [ _f("m.gguf", id=1, quant="Q5_K_M"), diff --git a/uv.lock b/uv.lock index 6fb0f32..1c98459 100644 --- a/uv.lock +++ b/uv.lock @@ -583,7 +583,7 @@ wheels = [ [[package]] name = "gen-worker" -version = "0.26.1" +version = "0.26.2" source = { editable = "." } dependencies = [ { name = "blake3" },