from dataclasses import asdict, dataclass
import json
@dataclass(frozen=True)
class Artifact:
repository: str
revision: str
task: str
license: str
parent: str | None = None
artifact = Artifact(repository="organization/model-name",
revision="0123456789abcdef",
task="text-generation", license="apache-2.0")
print(json.dumps(asdict(artifact), indent=2))39.5 Ecosystem
Most models in this book were trained from scratch, on Fashion-MNIST or on The Time Machine, so that every step stayed visible. A real project rarely starts that way. It starts from someone else’s work: a pretrained checkpoint, a public dataset, the code released with a paper. Suppose you want a model that sorts the support tickets of a small company. A search of the Hugging Face Hub for text classifiers returns more than a hundred thousand candidates, each with a download count and many with a model card and a benchmark score. Which one should you try first? Will its reported score hold on your tickets? And will the model you load next year be the one you evaluated today?
These are questions about evidence and identity rather than about training. Answering them means treating external artifacts the way a software engineer treats dependencies: find them where the community keeps them, judge them by measurements on your own task and not by rankings alone, and record which version you used and under which license. Without that record a result cannot be reproduced. A checkpoint downloaded in good faith can also run code on your machine unless its file format is checked first. This section follows the hardware sections because the choice of a model and the choice of a machine constrain each other. We look first at where models, datasets and papers are found, then at how to read benchmarks and leaderboards, at a few sources that keep a practitioner informed, and finally at how to pin, check and license what we download.
39.5.1 Sources of Models, Data, and Papers
39.5.1.1 Models
The Hugging Face Hub listed more than three million public models as of November 2026. Each model lives in a Git repository, with a model card and integrations with the libraries used in this book. Popularity does not establish suitability, so search by task, check recency and download counts, and read the model card. Several other sources complement the Hub:
- ModelScope, Alibaba’s hub, hosts a large part of the Chinese open-model ecosystem, with more than 280,000 models as of November 2026.
- Kaggle Models hosts curated weights wired into Kaggle’s competition and notebook infrastructure (Section 39.2).
- The Ollama library is a short, curated list of models packaged for a local runtime (Section 39.7).
timmprovides a broad collection of vision backbones, and Civitai hosts community image-generation checkpoints and LoRA adapters.
39.5.1.2 Datasets
Hugging Face Datasets (more than a million public datasets as of November 2026) and Kaggle cover most supervised needs. For pretraining-scale text, the lineage runs from raw Common Crawl through filtered derivatives. FineWeb held 15 trillion tokens at its 2024 release and more than 18.5 trillion after later versions added newer crawls, and the multilingual FineWeb2 applies the same pipeline to more than 1,000 languages. FineWeb is now a common open baseline for pretraining, the role that C4 played after its release with T5 in 2019. For image–text pairs, DataComp provides an alternative to LAION with an emphasis on controlled dataset construction and evaluation. Older and very large corpora are sometimes available only through Academic Torrents. Whatever the source, datasets have versions, licenses and documented failure modes, just as models do. Read a dataset’s documentation before adopting it.
39.5.1.3 Papers and Code
New work appears first on arXiv. Hugging Face Papers curates a daily front page and links papers to their code. It took over that role when Papers with Code, for years the index from papers to code and benchmarks, closed in July 2025; its address now redirects there, and its historical data survives as a frozen archive. The episode is a reason not to make a project depend on one external index. Semantic Scholar and alphaXiv help with search and discussion. Released code usually lives on GitHub, where issue history, recent commits and reported reproductions are evidence beyond the paper itself.
39.5.2 Benchmarks and Leaderboards
A leaderboard ranks models by one measurement, and a project needs a model that does well on another, its own task. A static benchmark also ages: models saturate it, or its questions leak into training data. Two retirements show both. The Open LLM Leaderboard, which ran fixed benchmarks on more than ten thousand open models, replaced its benchmarks in 2024 after models saturated them and was retired in 2025. In February 2026 OpenAI stopped reporting SWE-bench Verified, a set of real GitHub issues for coding agents, citing contamination and tests that reject correct fixes, and recommended the harder SWE-bench Pro instead. Model selection therefore combines several kinds of evidence:
- Arena, formerly LMArena and Chatbot Arena, ranks models by blind pairwise human preference. It measures what users of the site prefer on average, which may differ from what the target task needs.
- LiveBench limits contamination by releasing new questions regularly and withholding the newest ones.
- Capability benchmarks such as SWE-bench for coding agents follow a benchmark-per-capability pattern; mathematics, long context and safety have their own.
- Artificial Analysis measures quality, price and latency across models and providers.
- OpenRouter rankings order models by the number of tokens customers send them, a revealed preference that is most instructive where it disagrees with the quality leaderboards.
After forming a shortlist, build a small evaluation set from the target task and run each candidate on it. On the target task, models that sit next to each other on a leaderboard often differ by much more than their leaderboard scores do, and not always in the same order. The evaluation discipline used throughout this book (held-out data, meaningful baselines, error analysis) applies to choosing models just as it does to training them.
39.5.3 Information Sources
New models, papers and tools appear daily, and nobody can read every announcement. A small, deliberate set of sources is easier to judge than a continuous stream. One workable set, as of November 2026:
- r/LocalLLaMA, a community that reports open-weight releases, quantizations, hardware measurements and reproduction attempts.
- The daily selection of Hugging Face Papers instead of the hundreds of papers that arXiv receives each day.
- One newsletter, such as Andrew Ng’s The Batch, Jack Clark’s Import AI, or Sebastian Raschka’s Ahead of AI.
- The GPU MODE lectures and community for systems, and the EleutherAI community for open research.
Social media is where labs announce results. Use it to discover them, and cite the paper or the model card instead. The introduction of this chapter (Chapter 39) lists long-form references.
39.5.4 Managing External Artifacts
39.5.4.1 Pinned Revisions
A model is more than its weights. The tokenizer, preprocessing, configuration, license and revision all determine whether a result can be reproduced (Figure 39.5.1).
Hub repositories are Git repositories, and the branch main moves when the owner pushes a commit. To load the same files tomorrow, download a specific commit:
from huggingface_hub import snapshot_download
path = snapshot_download(
repo_id="organization/model-name",
revision="0123456789abcdef", # an immutable commit, not main
allow_patterns=["*.json", "*.safetensors"],
)
A small manifest records the model identity explicitly. In production, add file hashes, library versions and an evaluation record:
{
"repository": "organization/model-name",
"revision": "0123456789abcdef",
"task": "text-generation",
"license": "apache-2.0",
"parent": null
}
The same pinning applies to derived artifacts. A LoRA adapter without the revision of its base model is incomplete, and a quantized conversion (GGUF or AWQ, see Section 39.7) is a new artifact whose numerical fidelity to the source must be checked. The field parent of Artifact records the artifact that a derived one was made from.
39.5.4.2 Security and Licenses
A downloaded model is an input to your software supply chain, with the same security and licensing questions as any third-party library:
- Prefer safetensors, a container that holds only tensors. Legacy pickle-based checkpoints can execute arbitrary code when loaded. The Hub scans such files for known malicious patterns, which reduces the risk but does not remove it.
trust_remote_code=Trueruns Python from the repository on your machine. Read and pin that code, and use the flag only when the architecture requires it.- “Open” spans a wide range of licenses: permissive Apache or MIT weights, acceptable-use licenses with commercial thresholds, research-only releases, and gated models whose terms you accept per account. Record the license of the pinned revision, since a repository can change its license between revisions.
- Hub clients cache every file they download, and tens to hundreds of gigabytes in
~/.cache/huggingfaceare common.hf cache lslists the cache,hf cache rmdeletes a repository or revision, andhf cache pruneremoves revisions that no branch or tag points to any longer, along with incomplete downloads.
With these habits, a model found on a hub becomes a dependency you can justify, reproduce and audit. What they do not settle is whether the model is good enough for your task; only an evaluation on your own data answers that, and the exercises below show how large such an evaluation must be to separate two models.
39.5.5 Summary
Pretrained models, datasets and papers are found mostly on the Hugging Face Hub and its complements, and on arXiv. Preference rankings, contamination-resistant benchmarks, capability benchmarks and price-and-latency data each measure something different, and benchmarks are retired as models saturate or memorize them, so no single leaderboard settles a choice. The choice of a model rests on a small evaluation built from your own task, with error bars. Every external artifact is a supply-chain dependency: pin its revision, prefer safetensors, review remote code, and record its license and parent.
39.5.6 Exercises
Rating gaps on the Arena. Arena (formerly LMArena) fits the Bradley–Terry model of Section 15.3 to pairwise votes (Chiang et al. 2024) and reports the scores on the Elo scale. Ignoring ties, model A then beats model B with probability \[P(A \succ B) = \frac{1}{1 + 10^{-(R_A - R_B)/400}}, \tag{39.5.1}\] where \(R_A\) and \(R_B\) are the reported scores.
- Compute this probability for score gaps \(R_A - R_B\) of 10, 20, 50, and 100 points.
- Linearize \(P(A \succ B)\) around \(R_A = R_B\), and show that a gap \(R_A - R_B\) estimated from \(v\) independent votes between two models of similar strength has a standard error of about \(347/\sqrt{v}\) points. How many votes are needed before a 20-point gap lies two standard errors from zero?
- Model A leads model B by 20 points over all votes. On the 10% of the votes cast on prompts that resemble your task, B wins 60%. What is A’s win rate on the remaining votes? What does the result imply for choosing between A and B?
What a revision pins. A Hugging Face repository can be addressed by the branch
main, by a tag such asv1.0, by a pull-request ref such asrefs/pr/3, or by a 40-character commit hash.- Which of these identifiers always refer to the same files, and which can refer to different files tomorrow? Who can move each of them? Dataset repositories are addressed the same way, and
HuggingFaceFW/finewebkeeps each earlier version in a branch named after it, such asv1.3.0. Which identifier of that dataset should a training manifest record? - A pinned commit of a repository contains a
config.jsonwhoseauto_mapentry reads"AutoModelForCausalLM": "other-org/shared-code--modeling.MyModel". Withtrust_remote_code=True,transformersthen importsmodeling.pyfrom the repositoryother-org/shared-code. Readget_class_from_dynamic_moduleintransformers/dynamic_module_utils.py. Which revision ofmodeling.pyruns when you pass onlyrevisionwith your commit, and what must the manifest therefore record? - Name three inputs that lie outside all the repositories involved and still change the outputs of the loaded model when every repository is pinned to a commit.
- Which of these identifiers always refer to the same files, and which can refer to different files tomorrow? Who can move each of them? Dataset repositories are addressed the same way, and
[code] Code on load. Python’s
picklerebuilds an object by calling whatever callable the object’s__reduce__method returns, with the arguments it returns.- Write a class whose
__reduce__returns(print, ("code ran during load",)). Save an instance withtorch.saveinside a dictionary that also holds a tensor, and load the file withtorch.loadtwice: with the default arguments and withweights_only=False. What happens in each case? Which file of the repositoryopenai-community/gpt2, which also holdsmodel.safetensors,tf_model.h5, andflax_model.msgpack, is read by the same unpickling machinery? - With
weights_only=True,torch.loadstill interprets the pickle opcode stream but admits only an allowlist of classes and functions. In PyTorch 2.5.1 and earlier this restriction could be bypassed, so that loading a crafted file ran arbitrary code (CVE-2025-32434). Why does a safetensors loader need no such allowlist? Which risks remain when you load a safetensors model from a repository you do not trust?
- Write a class whose
[extended] Task-specific model selection. ● Choose a task you know well, such as answering support questions in your field or extracting fields from documents you handle.
- Shortlist three models using Arena or LiveBench, one benchmark for the capability your task needs, and Artificial Analysis. Where do the rankings disagree? Explain each disagreement by what the disagreeing leaderboards measure.
- Build an evaluation set from your task. Choose its size with the paired-comparison standard-error analysis of Section 36.5.2.6 for the smallest difference in accuracy that would change your choice. Add a random baseline and a simple heuristic baseline, such as the most frequent answer or keyword matching.
- Run the shortlist and the baselines on the set. Report each score with its standard error and each difference between two models with its paired standard error. Which differences are resolved, and does your ranking agree with the leaderboards?
Adapted from Chip Huyen, Machine Learning Systems Design, “Model selection”.
[code] A tensor container from scratch. ● A safetensors file consists of an 8-byte unsigned little-endian integer \(N\), an \(N\)-byte UTF-8 JSON header, and a byte buffer. The header maps each tensor name to its
dtype(such as"F32"or"I64"), itsshape, and itsdata_offsets, a pair[begin, end)of byte positions relative to the start of the buffer. An optional key__metadata__maps strings to strings. Tensors are stored in little-endian byte order and row-major layout.- Write
save_tensors(path, tensors, metadata)andload_tensors(path)for dictionaries of NumPy arrays, using onlyjson,struct, andnumpy. Check that a round trip reproduces the arrays. If thesafetensorspackage is installed, also check thatsafetensors.numpy.load_filereads your files. - Add an argument to
load_tensorsthat loads one named tensor throughnp.memmapwithout reading the rest of the buffer. - Read only the header of
model.safetensorsfrom revision607a30d783dfa663caf39e06633721c8d4cfcd7eofopenai-community/gpt2, using two HTTP range requests, and count the stored values from the shapes. Why does the count exceed the 124 million parameters of GPT-2 small? - List the checks that a loader must perform before it trusts a header from an unknown source. Build one malformed file that violates each check, and confirm that your loader rejects all of them.
- Write