saladday1's picture
code: sync from git
ff88a82 verified
Raw History Blame
6.88 kB
"""What a model family has to define. Everything else in hfeco is family-agnostic.
A family is a set of official models that have to be told apart from each other (H3 vs
H3-Image, M2 vs M2.5). Each one lives in hfeco/families/<key>.py and fills in the same
three tiers of evidence that hfeco/classify.py applies to every family:
1. structure the weights themselves: file hashes, tensor sizes and markers, value probes,
the architecture named by config.json or the GGUF header (`archs`)
2. statements declared base_model, model card text, sample media, creation date
3. names the repo name alone (low confidence at most)
To add one: write hfeco/families/<key>.py, register it in hfeco/families/__init__.py, run
scripts/build_reference.py --family <key>, then scripts/daily.py --family <key>, and point
its releases at it in hfeco/org.py (RELEASES). Storage, the daily job and the page pick it
up by its key.
"""
import json
import re
from dataclasses import dataclass, field
from pathlib import Path
from typing import Callable, Optional
@dataclass
class Member:
lineage: str # short label used everywhere, e.g. "H3-Image"
base: str # official repo id
modality: str # video | image | text | audio | ...
text_hint: Optional[re.Pattern] = None # how cards/names refer to this member specifically
tracked: bool = True # False: still classified (so its derivatives are kept out of
# the others), but not on the dashboard or in PR candidates
also: tuple = () # other official repos of the same release (M1-40k next to M1-80k)
@property
def repos(self):
return (self.base, *self.also)
@dataclass
class Arch:
"""A weight layout the family ships, as config.json (model_type / architectures) or a GGUF
header (general.architecture) names it. Members that share one layout (M2 ... M2.7) are told
apart by the other evidence; the hidden size keeps out test models that reuse the
architecture at toy sizes (expert or layer pruning leaves it unchanged)."""
members: tuple # lineages that ship this layout
names: re.Pattern # matched against model_type, architectures, general.architecture
hidden: Optional[int] = None # config hidden_size / GGUF <arch>.embedding_length
vocab: Optional[int] = None # config vocab_size / GGUF token count (Music3's LM is a Qwen3 with its own vocabulary)
strict: bool = False # the sizes must be stated, not just not contradict (for names other models share)
@property
def label(self):
return " / ".join(self.members)
@dataclass
class Family:
key: str # storage / URL key, e.g. "h3"
title: str # shown on the dashboard
members: list
default_member: Optional[str] # a generic mention of the family means this member (None: no such member)
# discovery
name_queries: list # Hub name search (substring of repo id)
fulltext_queries: list # Hub README full-text search
tag_filters: list = field(default_factory=list)
family_text: re.Pattern = None # any mention of the family in names/cards
name_hint: re.Pattern = None # names worth probing even without other signals
# structural evidence (tier 1)
archs: list = field(default_factory=list) # Arch per layout (checkpoints with a config / GGUF header)
own_llm: bool = False # the family ships language models itself (M series, Music3's LM): LLM-shaped
# weights count as its own unless their layout is another model's
sig_dims: set = field(default_factory=set) # hidden sizes that identify the family's
sig_names: re.Pattern = None # block tensors (with sig_names), for DiTs without a config
marker_rules: list = field(default_factory=list) # (regex on tensor names, lineage, reason, full_weights_only)
meta_rules: list = field(default_factory=list) # (regex on safetensors __metadata__, lineage, reason)
index_rules: list = field(default_factory=list) # (substring of model_index.json, lineage)
extra_structural: Optional[Callable] = None # fn(ev, ctx) -> [(lineage, reason)]
probe_names: list = field(default_factory=list) # tensor names for the value probe
probe_prefixes: tuple = ("model.diffusion_model.", "diffusion_model.", "transformer.", "model.", "")
probe_sources: list = field(default_factory=list) # (lineage, repo, folder) to build the reference
# tier 2: card text rules (regex on README, lineage, weight, reason, skip_for_text_llm)
card_rules: list = field(default_factory=list)
# tier 2: what a GGUF header says it was converted from (general.name / base_model; lineage, reason)
header_rules: list = field(default_factory=list)
# text models around the family
text_member: Optional[str] = None # lineage of an official text-model member (e.g. PE)
text_member_hint: Optional[re.Pattern] = None # card wording about the text member (tier 2 only)
text_member_name: Optional[re.Pattern] = None # the text member named in a repo id or tags
text_component: Optional[re.Pattern] = None # e.g. the family's own text encoder
text_component_why: str = "是这个家族自带的文本编码器"
component_names: Optional[re.Pattern] = None
native_quant: dict = field(default_factory=dict) # lineage -> regex of the member's own quant format
# Publishers with many ordinary repos: their few adult repos are hidden one by one, the rest stay
# on the page (otherwise an author with several adult repos is hidden entirely).
nsfw_author_exempt: set = field(default_factory=set)
_ref: dict = None
@property
def lineages(self):
return [m.lineage for m in self.members]
@property
def tracked(self):
return [m for m in self.members if m.tracked]
@property
def bases(self):
"""Every official repo of the family."""
return [r for m in self.members for r in m.repos]
def member(self, lineage):
return next(m for m in self.members if m.lineage == lineage)
def base_of(self, lineage):
return self.member(lineage).base
def lineage_of_base(self):
return {r: m.lineage for m in self.members for r in m.repos}
def reference_path(self):
return Path(__file__).parent / "families" / f"{self.key}_reference.json"
@property
def ref(self):
if self._ref is None:
p = self.reference_path()
self._ref = json.loads(p.read_text()) if p.exists() else {"sha256": {}, "probes": []}
return self._ref