classifier 2026-11-17.6 + labels
Browse files- cache/h3/enrich.jsonl +1 -1
- code/eval/compare.py +6 -3
- code/hfeco/classify.py +27 -11
- code/hfeco/enrich.py +2 -1
- code/hfeco/families/h3.py +3 -2
- code/hfeco/family.py +2 -1
- code/hfeco/store.py +4 -0
- code/octo-hf/hf_basemodel.py +37 -7
- code/scripts/job.sh +8 -0
- labels/h3/latest.parquet +2 -2
cache/h3/enrich.jsonl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 43492102
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:11b456c764771503b79dad6680cc52ec289e2bda2d66dcd74ccae8120793804c
|
| 3 |
size 43492102
|
code/eval/compare.py
CHANGED
|
@@ -21,14 +21,17 @@ from hfeco import store # noqa: E402
|
|
| 21 |
ap = argparse.ArgumentParser()
|
| 22 |
ap.add_argument("--family", default="h3")
|
| 23 |
ap.add_argument("--show", action="store_true", help="print every disagreement")
|
|
|
|
|
|
|
| 24 |
a = ap.parse_args()
|
| 25 |
|
| 26 |
lab = pd.read_parquet(store.LOCAL / "labels" / a.family / "latest.parquet").set_index(["kind", "repo_id"])
|
| 27 |
lab["evidence"] = lab.evidence.apply(json.loads)
|
| 28 |
hand = []
|
| 29 |
-
|
|
|
|
| 30 |
hand += json.load(open(p))
|
| 31 |
-
sample = {x["repo_id"]: x for x in json.load(open(ROOT / "eval" / "sample.json"))}
|
| 32 |
|
| 33 |
# Relations that count as the same answer for this check.
|
| 34 |
SAME_REL = {"no-weights": "no-weights", None: None}
|
|
@@ -58,7 +61,7 @@ df["is_h3_ours"] = df.ours_lin == "H3"
|
|
| 58 |
fam_rel = df[df.hand_lin.isin(["H3", "H3-Image", "H3-Image-PE"]) & df.lin_ok]
|
| 59 |
fam_rel = fam_rel.assign(rel_ok=fam_rel.hand_rel == fam_rel.ours_rel)
|
| 60 |
|
| 61 |
-
print(f"
|
| 62 |
print(f" lineage agreement: {df.lin_ok.mean():.1%} ({df.lin_ok.sum()}/{len(df)})")
|
| 63 |
tp = (df.is_h3_hand & df.is_h3_ours).sum()
|
| 64 |
fp = (~df.is_h3_hand & df.is_h3_ours).sum()
|
|
|
|
| 21 |
ap = argparse.ArgumentParser()
|
| 22 |
ap.add_argument("--family", default="h3")
|
| 23 |
ap.add_argument("--show", action="store_true", help="print every disagreement")
|
| 24 |
+
ap.add_argument("--set", default="sample", choices=["sample", "holdout"],
|
| 25 |
+
help="sample = the 100 repos used while tuning; holdout = 60 fresh repos labelled after the freeze")
|
| 26 |
a = ap.parse_args()
|
| 27 |
|
| 28 |
lab = pd.read_parquet(store.LOCAL / "labels" / a.family / "latest.parquet").set_index(["kind", "repo_id"])
|
| 29 |
lab["evidence"] = lab.evidence.apply(json.loads)
|
| 30 |
hand = []
|
| 31 |
+
pattern = "labels_part*.json" if a.set == "sample" else "holdout_labels_part*.json"
|
| 32 |
+
for p in sorted((ROOT / "eval").glob(pattern)):
|
| 33 |
hand += json.load(open(p))
|
| 34 |
+
sample = {x["repo_id"]: x for x in json.load(open(ROOT / "eval" / ("sample.json" if a.set == "sample" else "holdout.json")))}
|
| 35 |
|
| 36 |
# Relations that count as the same answer for this check.
|
| 37 |
SAME_REL = {"no-weights": "no-weights", None: None}
|
|
|
|
| 61 |
fam_rel = df[df.hand_lin.isin(["H3", "H3-Image", "H3-Image-PE"]) & df.lin_ok]
|
| 62 |
fam_rel = fam_rel.assign(rel_ok=fam_rel.hand_rel == fam_rel.ours_rel)
|
| 63 |
|
| 64 |
+
print(f"{a.set}: {len(df)} repos")
|
| 65 |
print(f" lineage agreement: {df.lin_ok.mean():.1%} ({df.lin_ok.sum()}/{len(df)})")
|
| 66 |
tp = (df.is_h3_hand & df.is_h3_ours).sum()
|
| 67 |
fp = (~df.is_h3_hand & df.is_h3_ours).sum()
|
code/hfeco/classify.py
CHANGED
|
@@ -16,7 +16,7 @@ import re
|
|
| 16 |
|
| 17 |
import numpy as np
|
| 18 |
|
| 19 |
-
VERSION = "2026-11-17.
|
| 20 |
DERIVED = {"adapter", "finetune", "merge", "quantized", "repackage", "mirror", "component"}
|
| 21 |
HF_RELATIONS = {"adapter", "finetune", "merge", "quantized"}
|
| 22 |
SAME = 1e-3 # probe distance below this = same weights (bf16 -> fp16 copies land at ~0)
|
|
@@ -25,7 +25,7 @@ LORA_KEY = re.compile(r"lora_[ABab]\b|lora_down|lora_up|lora\.(down|up)|\.lokr_|
|
|
| 25 |
re.I)
|
| 26 |
QUANT_NAME = re.compile(r"fp8|int8|int4|int6|nf4|nvfp4|mxfp|fp4|w4a\d|w6a8|w8a8|gptq|awq|svdq|nunchaku|"
|
| 27 |
r"q[2-8]_[0k]|q[2-8]_k|iq[1-4]|bnb|sdnq|convrot|[2-8]-?bit\b|gguf|exl2|hqq|quant", re.I)
|
| 28 |
-
MERGE_NAME = re.compile(r"merge|merged|mix\b|mixed|fused|\bfuse\b|blend", re.I)
|
| 29 |
REPACK_NAME = re.compile(r"comfy|diffusers|single[-_ ]?file|repack|split|bf16|fp16|fp32|pruned|mlx", re.I)
|
| 30 |
TUNED_NAME = re.compile(r"finetun|fine-tun|\bft\b|turbo|lightning|distill|\d+[-_ ]?steps?|\bacc\b|fast|"
|
| 31 |
r"lcm|dmd|pdmd|singularity|eros|nsfw|uncensor|heretic|abliterat", re.I)
|
|
@@ -77,7 +77,8 @@ def probe_match(probe, fam):
|
|
| 77 |
|
| 78 |
|
| 79 |
def sha_mirror(files, fam):
|
| 80 |
-
wb = [f for f in files or [] if f.get("sha256") and f.get("size", 0) > 1_000_000
|
|
|
|
| 81 |
if not wb:
|
| 82 |
return None
|
| 83 |
total = sum(f["size"] for f in wb)
|
|
@@ -145,7 +146,7 @@ def classify_model(r, ev, g, cutoff, fam):
|
|
| 145 |
is_text_llm = (bool(TEXT_LLM_TYPES.search(str(cfg.get("model_type") or ""))) or "ForCausalLM" in cfg_s
|
| 146 |
or bool(TEXT_LLM_TYPES.search(gguf_arch))
|
| 147 |
or (not is_dit and bool(re.search(r"layers\.N\.(self_attn|mlp|linear_attn)", patterns))))
|
| 148 |
-
readable = bool(keys.get("n")) or bool(ev.get("gguf"))
|
| 149 |
mi = json.dumps(ev.get("model_index") or {})
|
| 150 |
ctx = {"markers": markers, "sig": sig, "is_dit": is_dit, "is_lora": is_lora}
|
| 151 |
|
|
@@ -183,9 +184,13 @@ def classify_model(r, ev, g, cutoff, fam):
|
|
| 183 |
if m and not (created and cutoff.get(lin) and created < cutoff[lin]):
|
| 184 |
t1(lin, f"{why}({m.group(0)})")
|
| 185 |
break
|
|
|
|
|
|
|
|
|
|
| 186 |
pe_like = bool(fam.text_member and is_text_llm and (
|
| 187 |
-
fam.
|
| 188 |
-
or decl == fam.text_member)
|
|
|
|
| 189 |
if pe_like:
|
| 190 |
t1(fam.text_member, f"是文本大模型,且标明是 {fam.text_member}")
|
| 191 |
|
|
@@ -229,8 +234,13 @@ def classify_model(r, ev, g, cutoff, fam):
|
|
| 229 |
# ---- Family gate -------------------------------------------------------------------
|
| 230 |
fam_text = bool(fam.family_text and fam.family_text.search(text)) or any(
|
| 231 |
m.text_hint and m.text_hint.search(text) for m in fam.members if m.modality != "text")
|
| 232 |
-
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
author_hint = bool(fam.name_hint and fam.name_hint.search(name) and r["author"] in AUTHORS.get(fam.key, ()))
|
| 235 |
if not (decl or tier1 or is_dit or fam_text or author_hint):
|
| 236 |
return _res("unrelated", None, False, "medium", ["没有任何相关信号"], flags)
|
|
@@ -273,6 +283,10 @@ def classify_model(r, ev, g, cutoff, fam):
|
|
| 273 |
E.append(f"整仓权重与更早的 {copy_of} 逐字节相同,是重新上传")
|
| 274 |
rel = relation(r, ev, is_lora, is_dit or bool(weight_ev), is_text_llm, mirror, pm, name, E, pe_like, fam,
|
| 275 |
readable, other_dit, lineage)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
if rel == "tool":
|
| 277 |
E.append("权重不是来自这个家族,是给它用的周边工具")
|
| 278 |
if DISTILL_NAME.search(name) and rel in ("finetune", "adapter", "merge", "quantized"):
|
|
@@ -308,8 +322,9 @@ def relation(r, ev, is_lora, is_family_weights, is_text_llm, mirror, pm, name, E
|
|
| 308 |
bm = card.get("base_model")
|
| 309 |
multi = [b for b in bm if isinstance(b, str)] if isinstance(bm, list) else []
|
| 310 |
same = pm and pm[1] < SAME
|
| 311 |
-
|
| 312 |
-
|
|
|
|
| 313 |
return "merge"
|
| 314 |
if same:
|
| 315 |
return "repackage"
|
|
@@ -334,7 +349,8 @@ def relation(r, ev, is_lora, is_family_weights, is_text_llm, mirror, pm, name, E
|
|
| 334 |
return "finetune"
|
| 335 |
|
| 336 |
|
| 337 |
-
WEIGHT_EXT = (".safetensors", ".gguf", ".bin", ".pt", ".pth", ".ckpt", ".onnx", ".npz", ".sft"
|
|
|
|
| 338 |
|
| 339 |
|
| 340 |
def _weights(ev):
|
|
|
|
| 16 |
|
| 17 |
import numpy as np
|
| 18 |
|
| 19 |
+
VERSION = "2026-11-17.6"
|
| 20 |
DERIVED = {"adapter", "finetune", "merge", "quantized", "repackage", "mirror", "component"}
|
| 21 |
HF_RELATIONS = {"adapter", "finetune", "merge", "quantized"}
|
| 22 |
SAME = 1e-3 # probe distance below this = same weights (bf16 -> fp16 copies land at ~0)
|
|
|
|
| 25 |
re.I)
|
| 26 |
QUANT_NAME = re.compile(r"fp8|int8|int4|int6|nf4|nvfp4|mxfp|fp4|w4a\d|w6a8|w8a8|gptq|awq|svdq|nunchaku|"
|
| 27 |
r"q[2-8]_[0k]|q[2-8]_k|iq[1-4]|bnb|sdnq|convrot|[2-8]-?bit\b|gguf|exl2|hqq|quant", re.I)
|
| 28 |
+
MERGE_NAME = re.compile(r"merge|merged|mix\b|mixed|fused|\bfuse\b|blend|hybrid|graft", re.I)
|
| 29 |
REPACK_NAME = re.compile(r"comfy|diffusers|single[-_ ]?file|repack|split|bf16|fp16|fp32|pruned|mlx", re.I)
|
| 30 |
TUNED_NAME = re.compile(r"finetun|fine-tun|\bft\b|turbo|lightning|distill|\d+[-_ ]?steps?|\bacc\b|fast|"
|
| 31 |
r"lcm|dmd|pdmd|singularity|eros|nsfw|uncensor|heretic|abliterat", re.I)
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
def sha_mirror(files, fam):
|
| 80 |
+
wb = [f for f in files or [] if f.get("sha256") and f.get("size", 0) > 1_000_000
|
| 81 |
+
and f["name"].lower().endswith(WEIGHT_EXT)] # tokenizers etc. are shared widely
|
| 82 |
if not wb:
|
| 83 |
return None
|
| 84 |
total = sum(f["size"] for f in wb)
|
|
|
|
| 146 |
is_text_llm = (bool(TEXT_LLM_TYPES.search(str(cfg.get("model_type") or ""))) or "ForCausalLM" in cfg_s
|
| 147 |
or bool(TEXT_LLM_TYPES.search(gguf_arch))
|
| 148 |
or (not is_dit and bool(re.search(r"layers\.N\.(self_attn|mlp|linear_attn)", patterns))))
|
| 149 |
+
readable = bool(keys.get("n")) or bool(ev.get("gguf"))
|
| 150 |
mi = json.dumps(ev.get("model_index") or {})
|
| 151 |
ctx = {"markers": markers, "sig": sig, "is_dit": is_dit, "is_lora": is_lora}
|
| 152 |
|
|
|
|
| 184 |
if m and not (created and cutoff.get(lin) and created < cutoff[lin]):
|
| 185 |
t1(lin, f"{why}({m.group(0)})")
|
| 186 |
break
|
| 187 |
+
# A text model belongs to the text member only on weight evidence, a declaration, or the
|
| 188 |
+
# member's own name; "does prompt expansion" alone describes a tool, not a derivative.
|
| 189 |
+
name_tags = name + " " + " ".join(r["tags"])
|
| 190 |
pe_like = bool(fam.text_member and is_text_llm and (
|
| 191 |
+
(fam.text_member_name and fam.text_member_name.search(name_tags))
|
| 192 |
+
or (mirror and mirror[0] == fam.text_member and mirror[1] >= 0.5) or decl == fam.text_member)
|
| 193 |
+
and not (created and cutoff.get(fam.text_member) and created < cutoff[fam.text_member]))
|
| 194 |
if pe_like:
|
| 195 |
t1(fam.text_member, f"是文本大模型,且标明是 {fam.text_member}")
|
| 196 |
|
|
|
|
| 234 |
# ---- Family gate -------------------------------------------------------------------
|
| 235 |
fam_text = bool(fam.family_text and fam.family_text.search(text)) or any(
|
| 236 |
m.text_hint and m.text_hint.search(text) for m in fam.members if m.modality != "text")
|
| 237 |
+
name_fam = bool(fam.family_text and fam.family_text.search(name)) or any(
|
| 238 |
+
m.text_hint and m.text_hint.search(name) for m in fam.members)
|
| 239 |
+
if other_dit and is_lora and not tier1 and not decl:
|
| 240 |
+
return _res("unrelated", None, False, "high", ["是别的 DiT 模型的 LoRA(层的尺寸不对)"], flags)
|
| 241 |
+
component_for_family = bool(fam_text and fam.component_names and fam.component_names.search(name))
|
| 242 |
+
if other_dit and not tier1 and not decl and not name_fam and not component_for_family:
|
| 243 |
+
return _res("unrelated", None, False, "high", ["是别的模型的权重(层的尺寸不对),名字也没提到这个家族"], flags)
|
| 244 |
author_hint = bool(fam.name_hint and fam.name_hint.search(name) and r["author"] in AUTHORS.get(fam.key, ()))
|
| 245 |
if not (decl or tier1 or is_dit or fam_text or author_hint):
|
| 246 |
return _res("unrelated", None, False, "medium", ["没有任何相关信号"], flags)
|
|
|
|
| 283 |
E.append(f"整仓权重与更早的 {copy_of} 逐字节相同,是重新上传")
|
| 284 |
rel = relation(r, ev, is_lora, is_dit or bool(weight_ev), is_text_llm, mirror, pm, name, E, pe_like, fam,
|
| 285 |
readable, other_dit, lineage)
|
| 286 |
+
if rel == "tool" and not (decl or name_fam or component_for_family):
|
| 287 |
+
# Weights from another model and only the card mentions the family: an ad, a comparison,
|
| 288 |
+
# or training data made with it. Not part of the ecosystem count.
|
| 289 |
+
return _res("unrelated", None, False, "medium", ["权重来自别的模型,只在模型卡里提到这个家族"], flags)
|
| 290 |
if rel == "tool":
|
| 291 |
E.append("权重不是来自这个家族,是给它用的周边工具")
|
| 292 |
if DISTILL_NAME.search(name) and rel in ("finetune", "adapter", "merge", "quantized"):
|
|
|
|
| 322 |
bm = card.get("base_model")
|
| 323 |
multi = [b for b in bm if isinstance(b, str)] if isinstance(bm, list) else []
|
| 324 |
same = pm and pm[1] < SAME
|
| 325 |
+
meta_merge = bool(re.search(r"merg|graft", json.dumps(ev.get("st_meta") or {}), re.I))
|
| 326 |
+
if (card.get("base_model_relation") == "merge" or len(multi) >= 2 or meta_merge or MERGE_NAME.search(name)
|
| 327 |
+
or any(p.startswith("merge:") for p in r["hf_parents"])) and not (same and not MERGE_NAME.search(name)):
|
| 328 |
return "merge"
|
| 329 |
if same:
|
| 330 |
return "repackage"
|
|
|
|
| 349 |
return "finetune"
|
| 350 |
|
| 351 |
|
| 352 |
+
WEIGHT_EXT = (".safetensors", ".gguf", ".bin", ".pt", ".pth", ".ckpt", ".onnx", ".npz", ".sft", ".tflite",
|
| 353 |
+
".mlmodel", ".engine", ".pte")
|
| 354 |
|
| 355 |
|
| 356 |
def _weights(ev):
|
code/hfeco/enrich.py
CHANGED
|
@@ -14,7 +14,8 @@ from huggingface_hub import get_token, hf_hub_url
|
|
| 14 |
|
| 15 |
from . import hub
|
| 16 |
|
| 17 |
-
WEIGHT_EXT = (".safetensors", ".gguf", ".bin", ".pt", ".pth", ".ckpt", ".onnx", ".npz", ".sft"
|
|
|
|
| 18 |
MEDIA_VIDEO = (".mp4", ".webm", ".mov", ".gif", ".mkv")
|
| 19 |
MEDIA_IMAGE = (".png", ".jpg", ".jpeg", ".webp")
|
| 20 |
README_MAX = 12_000
|
|
|
|
| 14 |
|
| 15 |
from . import hub
|
| 16 |
|
| 17 |
+
WEIGHT_EXT = (".safetensors", ".gguf", ".bin", ".pt", ".pth", ".ckpt", ".onnx", ".npz", ".sft", ".tflite",
|
| 18 |
+
".mlmodel", ".engine", ".pte")
|
| 19 |
MEDIA_VIDEO = (".mp4", ".webm", ".mov", ".gif", ".mkv")
|
| 20 |
MEDIA_IMAGE = (".png", ".jpg", ".jpeg", ".webp")
|
| 21 |
README_MAX = 12_000
|
code/hfeco/families/h3.py
CHANGED
|
@@ -77,7 +77,8 @@ FAMILY = Family(
|
|
| 77 |
native_quant={"H3-Image-PE": re.compile(r"nvfp4|fp4|modelopt", re.I)}, # the official PE ships as NVFP4
|
| 78 |
text_member="H3-Image-PE",
|
| 79 |
text_member_hint=PE_TEXT,
|
|
|
|
| 80 |
text_component=re.compile(r"qwen3[-_.]?vl|text[-_ ]?encoder|conditioner", re.I),
|
| 81 |
-
component_names=re.compile(r"(^|[^a-z])(vae|tae|taeh3|text[-_ ]?
|
| 82 |
-
r"upscal|latent[-_ ]upscal|audio[-_]vae|clip|tokenizer|embeddings?)([^a-z]|$)", re.I),
|
| 83 |
)
|
|
|
|
| 77 |
native_quant={"H3-Image-PE": re.compile(r"nvfp4|fp4|modelopt", re.I)}, # the official PE ships as NVFP4
|
| 78 |
text_member="H3-Image-PE",
|
| 79 |
text_member_hint=PE_TEXT,
|
| 80 |
+
text_member_name=re.compile(r"h3[-_ ]?image[-_ ]?pe|image[-_]pe\b", re.I),
|
| 81 |
text_component=re.compile(r"qwen3[-_.]?vl|text[-_ ]?encoder|conditioner", re.I),
|
| 82 |
+
component_names=re.compile(r"(^|[^a-z])(vae|tae|taeh3|text[-_ ]?encoders?|conditioner|qwen3[-_.]?vl|"
|
| 83 |
+
r"upscal\w*|latent[-_ ]upscal\w*|audio[-_]vae|clip|tokenizer|embeddings?|decoder)([^a-z]|$)", re.I),
|
| 84 |
)
|
code/hfeco/family.py
CHANGED
|
@@ -51,7 +51,8 @@ class Family:
|
|
| 51 |
|
| 52 |
# text models around the family
|
| 53 |
text_member: Optional[str] = None # lineage of an official text-model member (e.g. PE)
|
| 54 |
-
text_member_hint: Optional[re.Pattern] = None
|
|
|
|
| 55 |
text_component: Optional[re.Pattern] = None # e.g. the family's own text encoder
|
| 56 |
component_names: Optional[re.Pattern] = None
|
| 57 |
native_quant: dict = field(default_factory=dict) # lineage -> regex of the member's own quant format
|
|
|
|
| 51 |
|
| 52 |
# text models around the family
|
| 53 |
text_member: Optional[str] = None # lineage of an official text-model member (e.g. PE)
|
| 54 |
+
text_member_hint: Optional[re.Pattern] = None # card wording about the text member (tier 2 only)
|
| 55 |
+
text_member_name: Optional[re.Pattern] = None # the text member named in a repo id or tags
|
| 56 |
text_component: Optional[re.Pattern] = None # e.g. the family's own text encoder
|
| 57 |
component_names: Optional[re.Pattern] = None
|
| 58 |
native_quant: dict = field(default_factory=dict) # lineage -> regex of the member's own quant format
|
code/hfeco/store.py
CHANGED
|
@@ -41,6 +41,10 @@ def read_raw(fam_key, day=None):
|
|
| 41 |
df = pd.concat([pd.read_parquet(f).assign(day=f.stem) for f in files], ignore_index=True)
|
| 42 |
for c in LIST_COLS:
|
| 43 |
df[c] = df[c].apply(json.loads)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
return df
|
| 45 |
|
| 46 |
|
|
|
|
| 41 |
df = pd.concat([pd.read_parquet(f).assign(day=f.stem) for f in files], ignore_index=True)
|
| 42 |
for c in LIST_COLS:
|
| 43 |
df[c] = df[c].apply(json.loads)
|
| 44 |
+
# pandas 3 reads missing strings as NaN; the classifier expects None.
|
| 45 |
+
for c in df.columns:
|
| 46 |
+
if c not in LIST_COLS and not pd.api.types.is_numeric_dtype(df[c]):
|
| 47 |
+
df[c] = df[c].astype(object).where(df[c].notna(), None)
|
| 48 |
return df
|
| 49 |
|
| 50 |
|
code/octo-hf/hf_basemodel.py
CHANGED
|
@@ -41,16 +41,23 @@ WHY = [
|
|
| 41 |
]
|
| 42 |
|
| 43 |
|
| 44 |
-
def candidates(fam, min_downloads, limit):
|
| 45 |
lab = pd.read_parquet(store.LOCAL / "labels" / fam.key / "latest.parquet")
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
df = lab.merge(raw, on="repo_id")
|
| 49 |
-
df["flags"] = df
|
| 50 |
df["evidence"] = df.evidence.apply(json.loads)
|
| 51 |
keep = df[(df.kind == "model") & df.declared_status.isin(list(REASON)) & (df.confidence == "high")
|
| 52 |
-
& ~df
|
| 53 |
& (df.gated == "False")]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
keep = keep.sort_values("downloads_30d", ascending=False).head(limit)
|
| 55 |
rows = []
|
| 56 |
for r in keep.itertuples():
|
|
@@ -62,6 +69,27 @@ def candidates(fam, min_downloads, limit):
|
|
| 62 |
return rows
|
| 63 |
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
def current_meta(repo):
|
| 66 |
try:
|
| 67 |
text = Path(hf_hub_download(repo, "README.md", force_download=True)).read_text()
|
|
@@ -159,16 +187,18 @@ if __name__ == "__main__":
|
|
| 159 |
ap.add_argument("--base")
|
| 160 |
ap.add_argument("--relation")
|
| 161 |
ap.add_argument("--submit", action="store_true", help="actually open the PR (default: dry run)")
|
|
|
|
|
|
|
| 162 |
a = ap.parse_args()
|
| 163 |
fam = families.get(a.family)
|
| 164 |
if a.cmd == "candidates":
|
| 165 |
-
print(json.dumps(candidates(fam, a.min_downloads, a.limit), ensure_ascii=False, indent=1))
|
| 166 |
elif a.cmd == "patch":
|
| 167 |
if a.repo and a.base: # a hand-written row, e.g. for testing on a sandbox repo
|
| 168 |
rows = [{"repo_id": a.repo, "reason": "hf-base-model-fix", "proposed_base_model": a.base,
|
| 169 |
"proposed_relation": a.relation, "evidence": []}]
|
| 170 |
else:
|
| 171 |
-
rows = candidates(fam, a.min_downloads, 10_000)
|
| 172 |
rows = [r for r in rows if not a.repo or r["repo_id"] == a.repo]
|
| 173 |
for r in rows[:a.limit]:
|
| 174 |
patch(r, fam, a.submit)
|
|
|
|
| 41 |
]
|
| 42 |
|
| 43 |
|
| 44 |
+
def candidates(fam, min_downloads, limit, include_relation=False):
|
| 45 |
lab = pd.read_parquet(store.LOCAL / "labels" / fam.key / "latest.parquet")
|
| 46 |
+
raw_all = store.read_raw(fam.key)
|
| 47 |
+
raw_all = raw_all[raw_all.day == raw_all.day.max()]
|
| 48 |
+
raw = raw_all[["repo_id", "downloads_all_time", "downloads_30d", "gated"]]
|
| 49 |
df = lab.merge(raw, on="repo_id")
|
| 50 |
+
df["flags"] = df["flags"].apply(json.loads)
|
| 51 |
df["evidence"] = df.evidence.apply(json.loads)
|
| 52 |
keep = df[(df.kind == "model") & df.declared_status.isin(list(REASON)) & (df.confidence == "high")
|
| 53 |
+
& ~df["flags"].apply(lambda f: "nsfw" in f or "copy" in f) & (df.downloads_all_time.fillna(0) >= min_downloads)
|
| 54 |
& (df.gated == "False")]
|
| 55 |
+
if not include_relation:
|
| 56 |
+
keep = keep[keep.declared_status != "wrong_relation"]
|
| 57 |
+
# A repo that already declares a community parent is fixed at the root of its chain, not here:
|
| 58 |
+
# adding the official base next to the parent would read as a merge on the Hub.
|
| 59 |
+
upstream = _member_upstreams(fam)
|
| 60 |
+
keep = keep[keep.repo_id.apply(lambda rid: not _declares_other_parent(rid, raw_all, fam, upstream))]
|
| 61 |
keep = keep.sort_values("downloads_30d", ascending=False).head(limit)
|
| 62 |
rows = []
|
| 63 |
for r in keep.itertuples():
|
|
|
|
| 69 |
return rows
|
| 70 |
|
| 71 |
|
| 72 |
+
def _member_upstreams(fam):
|
| 73 |
+
"""Repos the official members themselves declare as base (e.g. Qwen for the PE)."""
|
| 74 |
+
out = set()
|
| 75 |
+
for m in fam.members:
|
| 76 |
+
try:
|
| 77 |
+
card = api.model_info(m.base).card_data
|
| 78 |
+
except Exception:
|
| 79 |
+
continue
|
| 80 |
+
up = (card.to_dict() if card else {}).get("base_model")
|
| 81 |
+
out |= {up} if isinstance(up, str) else set(up or [])
|
| 82 |
+
return out
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _declares_other_parent(rid, raw_all, fam, upstream):
|
| 86 |
+
row = raw_all[(raw_all.repo_id == rid) & (raw_all.kind == "model")]
|
| 87 |
+
if row.empty:
|
| 88 |
+
return False
|
| 89 |
+
declared = set(row.iloc[0].card_base_model) | {p.split(":", 1)[1] for p in row.iloc[0].hf_parents}
|
| 90 |
+
return bool(declared - set(fam.bases) - upstream)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
def current_meta(repo):
|
| 94 |
try:
|
| 95 |
text = Path(hf_hub_download(repo, "README.md", force_download=True)).read_text()
|
|
|
|
| 187 |
ap.add_argument("--base")
|
| 188 |
ap.add_argument("--relation")
|
| 189 |
ap.add_argument("--submit", action="store_true", help="actually open the PR (default: dry run)")
|
| 190 |
+
ap.add_argument("--include-relation", action="store_true",
|
| 191 |
+
help="also propose base_model_relation fixes (off by default: authors chose them on purpose)")
|
| 192 |
a = ap.parse_args()
|
| 193 |
fam = families.get(a.family)
|
| 194 |
if a.cmd == "candidates":
|
| 195 |
+
print(json.dumps(candidates(fam, a.min_downloads, a.limit, a.include_relation), ensure_ascii=False, indent=1))
|
| 196 |
elif a.cmd == "patch":
|
| 197 |
if a.repo and a.base: # a hand-written row, e.g. for testing on a sandbox repo
|
| 198 |
rows = [{"repo_id": a.repo, "reason": "hf-base-model-fix", "proposed_base_model": a.base,
|
| 199 |
"proposed_relation": a.relation, "evidence": []}]
|
| 200 |
else:
|
| 201 |
+
rows = candidates(fam, a.min_downloads, 10_000, a.include_relation)
|
| 202 |
rows = [r for r in rows if not a.repo or r["repo_id"] == a.repo]
|
| 203 |
for r in rows[:a.limit]:
|
| 204 |
patch(r, fam, a.submit)
|
code/scripts/job.sh
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Entry point for the scheduled HF Job (image python:3.12, secret HF_TOKEN).
|
| 3 |
+
# Pulls the code from the dataset repo and runs the daily pipeline with --push.
|
| 4 |
+
set -euo pipefail
|
| 5 |
+
pip install -q "huggingface_hub>=1.17,<3" pandas pyarrow numpy requests httpx pyyaml
|
| 6 |
+
hf download MiniMaxAI/oss-ecosystem-data --repo-type dataset --include "code/*" --local-dir /w
|
| 7 |
+
cd /w/code
|
| 8 |
+
HFECO_LOCAL=/w/data python scripts/daily.py "${@:---push}"
|
labels/h3/latest.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e25a4e9d06e7e368d7295c24bf0eaebb8b37eeaa51223d487869fea50a025016
|
| 3 |
+
size 169338
|