- Distinguish open-weights, open-source and open-data releases and explain the OSI Open Source AI Definition's requirements.
- Compare Apache-2.0, MIT, Llama-style community licenses, Gemma-style terms and OpenRAIL licenses on commercial use, derivatives and use restrictions.
- Apply a licensing checklist to decide whether a model fits a commercial project.
- Implement safe model loading with safetensors, weights-only loading and pinned revisions.
- Evaluate a model card and record provenance in an AI bill of materials.
- Choose an appropriate license for your own model given inherited obligations and goals.
Before this: Parameters and Model Size, Local Runtimes and Model Formats, Distillation and Synthetic Data
The word "open" covers very different things in AI. One model comes with weights, training code and the full training data under a permissive license; another offers downloadable weights under a custom license that restricts certain uses, sets user-count thresholds, or dictates how derivatives must be named. If you build a product on a model, fine-tune one for a client, or release your own, the license is as much a design constraint as context length or memory footprint. This lesson gives you the vocabulary, the main license families, a method for reading terms, and the supply-chain hygiene needed to load third-party weights safely. It is an engineer's orientation, not legal advice: licenses change between model versions, and for any commercial decision you should read the current text and consult a lawyer.
Intuition: a recipe, a cake, and the ingredients list
Think of a trained model as a cake. Open weights means you are given the cake: you can eat it, slice it, add frosting (fine-tune it), and sometimes sell slices, under whatever conditions the baker attached. Open source in the traditional software sense means you also get the recipe and the freedom to bake, modify and share it for any purpose. Open data means you get the ingredients list and, ideally, the ingredients themselves. Most "open" models today are cakes with conditions. A handful come with the recipe and the ingredients.
Three layers of openness
| Layer | What is released | What it enables | Examples (check current releases) |
|---|---|---|---|
| Open weights | Trained parameters, inference code, usually a model card | Local inference, fine-tuning, quantisation, inspection | Llama, Gemma, Mistral, Qwen and DeepSeek families |
| Open source (in the OSI sense) | Weights plus training and inference code under OSI-approved style terms, plus detailed data information | Study and modify every stage; use for any purpose | Models released with full code and permissive terms |
| Open data | The training datasets (or reproducible recipes to rebuild them) | Full reproduction, data audits, research on data effects | AI2's OLMo with the Dolma corpus; EleutherAI's Pythia with the Pile |
The OSI Open Source AI Definition
The Open Source Initiative (OSI), steward of the Open Source Definition for software, published version 1.0 of the Open Source AI Definition in October 2024. It carries over the four freedoms of free software to AI systems: to use the system for any purpose without asking permission, to study how it works, to modify it, and to share it with or without modifications. To make those freedoms practical it requires access to the "preferred form for making modifications", which it spells out as three components:
- Data information: sufficiently detailed information about the training data (sources, selection, processing, labelling) that a skilled person could build a substantially equivalent system. It does not strictly require publishing every training document, a compromise that drew criticism from those who argue open source AI must include the data.
- Code: the complete source used to train and run the system, including data processing and filtering, under OSI-approved licenses.
- Parameters: the weights and configuration, under OSI-approved terms.
The practical consequence: licenses that restrict who may use a model or for what purpose (user thresholds, field-of-use bans) are not open source under this definition, even if the weights are free to download. OSI has said this explicitly about Meta's Llama licenses. "Open weights" is the accurate term for most downloadable models.
The main license families
Permissive: Apache-2.0 and MIT
- MIT is a few short paragraphs: do almost anything, including commercial use, modification and sublicensing, provided you keep the copyright and license notice. No warranty.
- Apache-2.0 is similar in spirit but longer and more explicit. You must include the license, keep copyright and attribution notices, carry forward any
NOTICEfile, and state significant changes you made. Importantly, it includes an express patent license from contributors, with a termination clause if you sue a contributor over patents in the work. Many companies prefer Apache-2.0 for that patent clarity.
Many open-weights models from Mistral, Qwen, Microsoft's Phi line, DeepSeek (R1 was released under MIT) and others have used Apache-2.0 or MIT. These permit commercial use, fine-tuning, distillation and redistribution with attribution, which makes them the easiest to build on. Note that a permissive license on the weights does not by itself settle questions about the training data.
Custom community licenses: the Llama example
Meta's Llama models ship under model-specific community license agreements plus an Acceptable Use Policy (AUP). The Llama 3.x-era licenses grant a broad, royalty-free license to use, reproduce, modify and distribute the model and derivatives, with conditions that include:
- A scale threshold: if your products or services had more than 700 million monthly active users on the model version's release date, you must request a separate license from Meta.
- Attribution: redistributions must include a copy of the license, and products or services using the model must prominently display "Built with Llama".
- Naming: if you use the model or its outputs to create, train, fine-tune or otherwise improve an AI model that you distribute, its name must begin with "Llama". (Llama 3.1, for example, permits using outputs to improve other models on these terms, whereas the original Llama 3 license did not allow it for non-Llama models.)
- Acceptable use: the AUP, incorporated by reference, forbids categories of use such as illegal activity, certain weapons and critical-infrastructure applications, and deceptive impersonation.
- Version-specific terms: versions have differed on points such as the outputs clause above and on certain regional or multimodal restrictions. Always read the license for the exact version you use.
For most companies these terms permit commercial use, but they are not open source, they impose obligations that flow through to your users and derivatives, and Meta can update the AUP.
Gemma Terms of Use
Google's Gemma models up to Gemma 3 were released under the custom Gemma Terms of Use with a Prohibited Use Policy; Gemma 4 (2026) switched to Apache-2.0, so as of November 2026 the license depends on which generation you use. Under the Gemma Terms of Use, commercial use, modification and redistribution are permitted, but the use restrictions must be passed on: if you distribute Gemma or a derivative (including a fine-tune or, under the terms' definitions, a model trained on its outputs for certain purposes), you must include the use restrictions in your agreement with recipients and provide them with a copy of the terms. Google states it claims no rights over outputs you generate, and it reserves the right to restrict usage that it believes violates the terms. Gemma's move from custom terms to Apache-2.0 is a concrete example of why you must check the terms attached to each specific release: vendors change license strategy between generations.
OpenRAIL: responsible AI licenses
RAIL (Responsible AI Licenses) and its OpenRAIL variants pair a permissive, royalty-free grant with use-based restrictions listed in an attachment, for example prohibitions on using the model to harm minors, generate or spread verifiably false information intended to harm others, or provide medical advice and interpret medical results. The key mechanism is that the restrictions must be carried forward into the license of any derivative or redistribution. The BigScience BLOOM model used a RAIL license, and Stable Diffusion's early releases used CreativeML OpenRAIL-M (the "M" denotes that the licensed artifact is the model). A redistributor may use different terms for a derivative but must keep the use-based restrictions. Like the Llama and Gemma terms, these are not open source under OSI's definition because they restrict fields of use.
Non-commercial and research-only licenses
Some models are released under research-only or non-commercial terms (including Creative Commons NC licenses applied to weights). These are fine for experiments and academic work but rule out production use. Read carefully: "non-commercial" often includes internal business use.
What you can and can't do commercially: a working checklist
When evaluating a model for a product, answer these questions from the license text itself:
- Commercial use: allowed at all? Any revenue or user thresholds?
- Field-of-use restrictions: an AUP or attachment of prohibited uses? Does your use case touch any category (medical, legal, biometric, surveillance, critical infrastructure)?
- Redistribution: may you ship the weights (for example on-device)? What must accompany them (license copy, notices, use restrictions)?
- Derivatives: are fine-tunes, merges, quantisations and distilled models "derivatives"? What naming, attribution or license-inheritance rules apply?
- Outputs: any restrictions on using generated outputs, especially to train other models?
- Attribution and branding: required notices or "Built with" displays?
- Termination and changes: can the licensor update policies by reference? What triggers termination?
- Patents and indemnity: is there a patent grant? Any indemnity (rare for open weights; sometimes offered by commercial hosting providers)?
- Data and third-party rights: what does the model card say about training data, and does any of it raise copyright or privacy questions for your use?
Worked example: choosing a base model for a client project
A startup asks you to fine-tune a 7 to 9B model for an on-device customer-support assistant. It will be embedded in their mobile app (about 2 million users), they want to sell the fine-tuned model to other businesses, and some of their clients are healthcare providers.
- Shortlist three candidate families of similar quality from current benchmarks and the site's AI Index: one Apache-2.0 model, one under a Llama-style community license, one under terms like the Gemma Terms of Use.
- Scale threshold: 2 million users is far below 700 million, so the Llama-style threshold is not an issue.
- Redistribution and derivatives: selling the fine-tune means distributing a derivative. The Apache-2.0 model needs the license, notices and a statement of changes. The Llama-style model needs the license copy, "Built with Llama" display, and a model name beginning with "Llama". The model under Gemma-style terms requires passing the use restrictions to every customer contractually.
- Use restrictions: healthcare clients may touch medical-advice categories in AUPs or prohibited-use policies. Check exact wording; a support bot for appointment scheduling is very different from symptom triage.
- Decision: if quality is comparable, the Apache-2.0 model minimises ongoing obligations and branding constraints. If a restricted-license model is clearly better, it can still be viable, but budget for compliance (notices, naming, contract terms) and legal review.
- Record the model name, exact version and revision hash, license text and date reviewed in the project's documentation.
Model cards
A model card (Mitchell et al., 2019) is structured documentation shipped with a model: intended uses and out-of-scope uses, training data summary, evaluation results across relevant groups and conditions, limitations and biases, environmental cost, and license. On the Hugging Face Hub the card is the repository's README.md with a YAML metadata header that records the license, base model, datasets and tags. Read cards critically: they are self-reported, and a missing data section is itself informative. When you publish a model, write a card that a downstream engineer could use to decide whether your model fits their task.
Provenance and supply-chain safety
Downloading weights is downloading code-adjacent artefacts from the internet. Treat it like adding a dependency.
Serialisation formats: pickle versus safetensors
PyTorch's traditional checkpoint format uses Python's pickle, and unpickling can execute arbitrary code. A malicious .bin or .pt file can run commands on your machine the moment you load it. safetensors, developed by Hugging Face, stores only tensors and a JSON header, so loading cannot execute code; it also supports fast, memory-mapped, lazy loading. GGUF, used by llama.cpp-family runtimes, is likewise a data-only format.
from safetensors.torch import load_file, save_file
import torch
weights = {"linear.weight": torch.randn(4, 4), "linear.bias": torch.zeros(4)}
save_file(weights, "model.safetensors")
loaded = load_file("model.safetensors") # no code execution possible
print({k: tuple(v.shape) for k, v in loaded.items()})
# If you must read a legacy pickle checkpoint, restrict it to tensors:
# state = torch.load("legacy.pt", weights_only=True)
Since PyTorch 2.6, weights_only=True is the default for torch.load, which refuses to unpickle arbitrary objects; pass it explicitly anyway so the intent is clear and older versions behave safely.
Remote code
Some Hugging Face models need custom architecture code and require trust_remote_code=True. That flag downloads and runs Python from the repository. Only enable it for publishers you trust, read the code, and pin a specific commit with the revision= argument so the code cannot change under you.
Verifying publishers and integrity
- Use official organisations on model hubs and check for verified-organisation badges; typo-squatted names ("meta-llama" versus look-alikes) exist.
- Pin revisions: reference a commit hash, not just
main, in production configs. - Check hashes of downloaded files against published checksums, and mirror approved models into an internal registry.
- Scan repositories with available malware and pickle scanners; prefer safetensors or GGUF releases.
- Be wary of re-uploads, merges and quantisations by unknown accounts: the license still applies, the weights may have been tampered with (for example backdoored with trigger phrases), and the declared base model may be wrong.
- Track an AI bill of materials: model, version, hash, license, data provenance, and fine-tuning datasets, the same way you track software dependencies.
Choosing a license for your own model
When you release weights you have trained or fine-tuned:
- Check what you inherit. A fine-tune of a Llama-licensed model must follow the Llama license; a derivative of an OpenRAIL model must carry its use restrictions; Apache-2.0 bases leave you free to choose, subject to notices.
- Check your data. Training data licenses (for example non-commercial datasets) and model-output terms may constrain how you can license the result.
- Decide your goal. Maximum adoption and simplicity favours Apache-2.0 (patent grant) or MIT. Wanting to bind downstream uses favours a RAIL-style license, at the cost of not being open source and of extra friction for adopters. Wanting to share for research only favours a non-commercial license.
- Publish a complete model card with license, intended use, data summary, evaluations and limitations, and release in safetensors.
- Consider the full open-source standard: releasing code and data information under OSI-compatible terms makes your model genuinely reproducible and widely trusted.
Common pitfalls
- Assuming "open" means "open source". Read the license; most popular open-weights models carry use restrictions.
- Reading the license of the wrong version. Terms change between generations and sometimes between sizes in the same family.
- Forgetting that derivatives inherit obligations, including quantised and merged models you redistribute.
- Loading pickle checkpoints from unknown sources, or enabling
trust_remote_codewithout pinning and reading the code. - Ignoring output and distillation clauses when generating training data.
- Not recording versions and hashes, which makes later audits and incident response impossible.
In practice
Mature teams maintain an approved-models list reviewed by legal and security, with each entry recording license, version hash, permitted uses and required notices. Engineers pull models only from an internal mirror, in safetensors or GGUF, with revisions pinned. Before any customer-facing release, they confirm attribution and naming obligations, propagate required use restrictions into customer terms, and ship a model card. Licensing landscapes shift quickly, so re-check terms at each model upgrade. Nothing here is legal advice; for commercial decisions, read the current license text and consult a qualified lawyer.
Key takeaways
- Most downloadable models are open weights with conditions, not open source under the OSI definition.
- The OSI Open Source AI Definition requires freedom to use, study, modify and share, plus data information, code and parameters.
- Permissive licenses (Apache-2.0, MIT) are simplest to build on; Apache-2.0 adds an explicit patent grant.
- Custom licenses such as Llama's and the Gemma Terms of Use add thresholds, acceptable-use policies, attribution, naming or pass-through obligations that derivatives inherit.
- Load weights in safetensors or GGUF, pin revisions, and treat trust_remote_code as running someone else's code.
- Licensing is version-specific and changes; read the current text and get legal advice for commercial decisions.
Terms in this lesson
- Open weights
- A release in which trained model parameters are downloadable, regardless of the license conditions attached.
- Open Source AI Definition (OSAID)
- OSI's 2024 definition requiring freedoms to use, study, modify and share an AI system, with data information, code and parameters available.
- Acceptable Use Policy (AUP)
- A document incorporated into a model license that lists prohibited uses of the model.
- OpenRAIL
- A family of royalty-free model licenses that include use-based restrictions which must be passed on to derivatives.
- Patent grant
- An explicit license from contributors to use their patents embodied in the work, as provided by Apache-2.0.
- Model card
- Structured documentation of a model's intended use, data, evaluations, limitations and license.
- safetensors
- A tensor serialisation format that stores only data and metadata, so loading it cannot execute code.
- trust_remote_code
- A Hugging Face loading flag that downloads and executes model-specific Python code from the repository.
- AI bill of materials
- A record of the models, versions, hashes, licenses and datasets that make up an AI system.
Check your understanding
- 1.
Under the OSI Open Source AI Definition 1.0, why is a license with a field-of-use acceptable use policy not open source?
- 2.
Which license includes an express patent license from contributors?
- 3.
You fine-tune a Llama 3.x model and release it publicly. Under the Llama 3.x-era community licenses, which is required?
- 4.
A colleague downloads
model.binfrom an unknown account and callstorch.loadon it with default settings in an old PyTorch version. What is the main risk? - 5.
For a commercial product where you want minimal ongoing obligations and comparable quality is available, which base-model license is usually easiest?
Exercises
Work each problem before opening the solution.
- Exercise 1Core
Classify each release as open data, open source (OSI sense), or open weights only, and justify briefly: (a) weights under Apache-2.0, training code released, a detailed data description and the full dataset released; (b) weights downloadable under a license banning use by companies above a user threshold; (c) weights under MIT, no training code, no information about data.
Show solution
(a) Open source and open data: permissive terms for weights and code, data information and the data itself are available, so all four freedoms are practical.
(b) Open weights only: the user threshold restricts who may use it, violating the any-purpose freedom.
(c) Open weights only (permissively licensed): the license itself is permissive, but without training code and data information the OSI definition's preferred form for modification is not provided, so it does not meet the Open Source AI Definition.
- Exercise 2Core
Write a Python script that (1) saves a small PyTorch state dict to safetensors, (2) computes the file's SHA-256 hash, and (3) reloads it only if the hash matches an expected value. Explain why this protects against tampering in transit.
Show solution
import hashlib import torch from safetensors.torch import save_file, load_file def sha256(path, chunk=1 << 20): h = hashlib.sha256() with open(path, "rb") as f: for block in iter(lambda: f.read(chunk), b""): h.update(block) return h.hexdigest() state = {"w": torch.randn(3, 3), "b": torch.zeros(3)} save_file(state, "m.safetensors") expected = sha256("m.safetensors") # in practice: published by the trusted source def safe_load(path, expected_hash): actual = sha256(path) if actual != expected_hash: raise ValueError(f"hash mismatch: {actual}") return load_file(path) print(sorted(safe_load("m.safetensors", expected).keys())) # ['b', 'w']The hash ties the file to the exact bytes the trusted publisher released; any modification (a swapped or backdoored tensor) changes the hash, so loading is refused. safetensors additionally guarantees that even an unexpected file cannot execute code during loading. Note the hash only helps if you obtain the expected value over a trusted channel.
- Exercise 3Core
A client wants to distribute a quantised version of a Gemma-family model released under the Gemma Terms of Use inside their desktop app, and separately sell API access to a fine-tune of an OpenRAIL-M model. List the licensing obligations you would check for each, in the form of a short checklist.
Show solution
Gemma-family quantised model in an app:
- Confirm which terms apply to that exact release (earlier Gemma generations used the Gemma Terms of Use; Gemma 4 uses Apache-2.0).
- A quantised model is a derivative/redistribution: include a copy of the terms and the required notices.
- Pass the use restrictions (Prohibited Use Policy) to end users, e.g. in the app's EULA.
- Ensure the app's use cases do not fall in prohibited categories.
- Note that terms incorporate policies the licensor can update; set a review cadence.
OpenRAIL-M fine-tune served via API:
- Read the attachment of use-based restrictions and confirm the service does not enable them.
- Carry the use restrictions into the API's terms of service for customers.
- Determine whether the fine-tune is a derivative that must be licensed under terms at least as restrictive if weights are ever distributed.
- Keep required attribution and notices.
Both: record model version, hash and license text in the AI bill of materials, and get legal review before launch.
- Exercise 4Challenge
Design a minimal internal 'model intake' policy for a 50-person company that wants to use open-weights models. Cover approval, storage, loading, documentation and re-review, and write a short Python function that refuses to load any Hugging Face model not on an allowlist of (repo_id, revision) pairs.
Show solution
Policy outline:
- Approval: any new model needs a ticket with repo ID, exact revision hash, license name and link, intended use, and confirmation that the use is outside any AUP/prohibited-use categories; approved by one engineering lead and legal for commercial use.
- Storage: approved models are mirrored to an internal registry or bucket; production systems pull only from the mirror.
- Format and loading: safetensors or GGUF only; trust_remote_code disallowed unless the code is reviewed and pinned; torch.load only with weights_only=True.
- Documentation: each entry has a model card summary, license obligations (attribution, naming, pass-through restrictions), and SHA-256 hashes, forming the AI bill of materials.
- Re-review: on every version upgrade, and at least annually, since licenses and policies change.
from transformers import AutoModelForCausalLM, AutoTokenizer ALLOWED = { ("Qwen/Qwen2.5-0.5B-Instruct", "<pinned-commit-hash>"), } def load_approved(repo_id, revision): if (repo_id, revision) not in ALLOWED: raise PermissionError(f"{repo_id}@{revision} is not approved") tok = AutoTokenizer.from_pretrained(repo_id, revision=revision) model = AutoModelForCausalLM.from_pretrained( repo_id, revision=revision, use_safetensors=True, trust_remote_code=False) return tok, modelThe function enforces both the repository and the exact revision, refuses pickle weights via use_safetensors=True, and never runs repository code. Replace the placeholder with a real commit hash from the model's history when approving it.
Further reading
Go further
Sources
- Open Source Initiative, The Open Source AI Definition 1.0
- Meta, Llama 3.1 Community License Agreement
- Google, Gemma Terms of Use
- Responsible AI Licenses (RAIL) initiative
- Apache License, Version 2.0
- Hugging Face safetensors documentation
- Open Source Initiative, Meta's LLaMa license is still not Open Source
- BigScience, The BigScience RAIL License (OpenRAIL-M)
- PyTorch dev-discuss: torch.load flipped to weights_only=True by default (2.6)
- The AI Track, Google launches Gemma 4 open models and switches to Apache 2.0 (April 2026)
- Gemma Terms of Use (24 March 2025 version, mirror)
Fact-checked and last reviewed 2026-11-05