程式碼庫採用 Apache-2.0,執行時下載的模型當時沒有授權
The repo was Apache-2.0. The model it downloaded at runtime had no license at all.
作者發現,一個採用 Apache-2.0 的 ML 項目,其推理程式預設下載的深度模型當時沒有授權聲明,這是他凍結自助版產品的原因之一。文章提供核查清單和 Python 腳本,示範如何檢查實際載入的模型、訓練設定中的基礎模型,以及 API 回應的重新導向。
In July I was planning a small commercial tool that turns a single character illustration into a layered, rig-ready file. The heavy lifting was going to come from an open-source research project I'd found on GitHub. It did what I needed on straightforward full-body characters, although it struggled with a voluminous costume and with a character whose face was hidden. The repository had an Apache-2.0 LICENSE file at the top level.
I almost stopped checking there. I'm glad I didn't, because the part of that project that actually produced the output wasn't covered by that file at all. One of the two models its inference script downloads at runtime had no license of any kind. Not a restrictive license. Not a non-commercial license. Nothing.
That finding was one of the two reasons I froze the self-serve version of the product. This post is about how I found it, the two tools that gave me a wrong or misleading answer along the way, and the checklist I use now.
I'm not a lawyer, and nothing here is legal advice. It's an engineering post about where the license information actually lives in an ML project, and how easy it is to read the wrong layer.
Update (November 2026). What follows is what I found in July. When I re-checked just before publishing, the picture had changed: in late September the maintainers added license terms to both of the models the inference script downloads. Both model cards now declare
openrail++. They state that the maintainers' own contributions are Apache-2.0, that the weights also inherit the licenses of the models they were derived from, that commercial use is permitted, and that anyone distributing the weights or a derivative of them, or hosting them as a service, has to pass the use restrictions on. My project log never records my inquiry as sent, so I'm not claiming any part in the change. I've kept the July account as it happened, because how the gap showed up is the point of this post.
The setup: three layers, one LICENSE file
When you adopt an ML project, you are not adopting one thing. You are adopting at least three:
- The code in the repository. This is what the top-level LICENSE file covers.
-
The code dependencies. Everything in
requirements.txt, plus anything vendored into subfolders. - The model weights. Usually not in the repository at all. They are downloaded at runtime from a model hub, by name.
Layers 1 and 2 behave like the open-source world most of us are used to. Layer 3 is where it gets strange, because the weights are a separate artifact, published separately, often by a different account, with their own license metadata — or without any.
The project I was evaluating was clean on the first two layers. I went through the dependency list and checked licenses one by one — mostly against each project's own repository, sometimes against the license file shipped in the installed package. A few of Hugging Face's own supporting packages I didn't check repository by repository, and I marked them that way. Everything I did check was Apache-2.0, MIT, or BSD. No non-commercial dependency turned up on the core path.
Then I opened the inference script.
Where the real dependency was hiding
The script that turns an input image into the layered output takes the models it uses as command-line arguments, with defaults. Here are the two lines that matter, copied from the file with the repository names redacted:
parser.add_argument('--repo_id_layerdiff', default='<org-a>/<generation-model>')
parser.add_argument('--repo_id_depth', default='<user-b>/<depth-model>')
Those two defaults are the whole product. One model generates the separated layers; the other is a depth-estimation model. When you run the script with no flags, both are fetched from Hugging Face by repository ID.
Neither of them is mentioned in the top-level LICENSE file, and that's expected. The LICENSE file covers the code that calls from_pretrained. It says nothing about what from_pretrained returns.
So I looked each model up.
The generation model had an apache-2.0 license tag on its Hugging Face page. That looked fine at first.
The depth model showed "No model card." No license tag. No README. No text of any kind explaining terms of use.
Why I didn't read "no license" as "no restrictions"
This is the misreading I want to flag most strongly, because it's the intuitive one. When a page shows no license, it feels like there's nothing to comply with. The way I read it — and I want to stress this is an engineer's working assumption, not legal advice — is closer to the opposite: nobody has granted you anything.
A license is the document that gives you permission to do things you otherwise might not be allowed to do — copy, modify, redistribute, use commercially. The common working assumption for unlicensed code is "all rights reserved," and the risk that weights get treated the same way was enough for me. How unlicensed model weights should actually be treated legally is a question I couldn't answer, and I noted it as exactly that.
It helps to compare it with a case that looks scarier but felt more manageable to me. Several popular base models are released under OpenRAIL-style licenses. As I understand them, those licenses allow commercial use but attach a list of use restrictions (no generating certain kinds of harmful content, and so on) and ask you to pass those restrictions on to your own users. That's real work: your terms of service have to carry the restrictions forward. But at least the license tells you what it expects, so there's something to comply with.
An unlicensed model gives you nothing to comply with. There is no clause to copy into your terms. The ways forward I could see were:
- get explicit permission from the author,
- replace the model with one that has a usable license, or
- retrain an equivalent model yourself from a base whose license you can follow.
So in my notes, I ended up separating these sharply. This is the triage I used for my own planning, not a legal ruling:
| What the model page shows | How I treated it for a commercial product |
|---|---|
| Permissive license (Apache-2.0, MIT) | Probably fine, subject to the license's own terms |
| OpenRAIL-style license | Conditional: carry the restrictions into my terms, get a review |
| Non-commercial license | Out |
| No license at all | Out until someone grants permission explicitly |
The last row is the one that's easy to read as "the first row, but simpler."
The tag that was there wasn't the whole story either
The generation model, with its clean apache-2.0 tag, turned out to need a second look too.
The project ships its training configuration files in the repository. The fine-tuning config for that generation model contains this line (base model redacted):
pretrained_model_name_or_path: <base-model>
The base model named there is published under an OpenRAIL++-M license. So the weights I'd be downloading were a fine-tune of a model whose license carries use restrictions and a requirement to pass them downstream — and the fine-tune itself was tagged Apache-2.0.
Whether a fine-tune can be relicensed in a way that drops the base model's restrictions is a legal question I can't answer. I wrote it down as "conditionally usable, needs review" rather than "Apache-2.0, fine." The point for this post is narrower: a license tag on a model hub is metadata the uploader chose. It's self-reported. It isn't checked against the model's lineage by anyone. If you want to know what you're really inheriting, the training config is a better source than the tag. (When I re-checked in November, the model card declared that base model and carried openrail++ instead.)
The same pattern showed up one level away, in a different project I'd evaluated the day before: the main repository was MIT, but it depended on a face-analysis library licensed for non-commercial use. The headline license was permissive; the thing doing the work wasn't. After two of these in two days, I stopped treating the top-level LICENSE as a summary of anything beyond the code it sits next to.
The redirect my tool said wasn't there
There was one more wrinkle, and it's the one I learned the most from.
While I was preparing to contact the author of the depth model, a routine check turned up something odd: opening the model's page under the original account seemed to show it under an organization's name instead. That mattered. If the model had been moved to an organization, then who to ask, and who could grant permission, might have changed too.
I asked my AI assistant to confirm whether the old URL redirected. It fetched the page with its built-in web tool and reported back that there was no redirect.
That contradicted the earlier observation, so I had it check again using the raw HTTP headers instead of the tool's summary:
$ curl -I https://huggingface.co/<user-b>/<depth-model>
... 307
location: /<org-a>/<depth-model>
(Trimmed to the two parts that mattered, with names redacted.) A 307 with a Location header pointing at the organization's namespace. The API endpoint for the old path returned the same kind of redirect to the same model. The old path no longer had anything behind it; it was purely a forward.
I don't know exactly how the web-fetch tool reached its answer. My best guess is that it followed the redirect, fetched the final page, and summarized that page — and "is there a redirect?" isn't a question about the content of the final page, so the summary had nothing to say about it and "no" filled the gap. Whatever the mechanism, the lesson was the same: the tool's summary is a processed product, and the raw headers are the primary data. Getting them took one command.
At the time, the move didn't change the conclusion. I pulled the API JSON for the model at its new location: there was no license key, no cardData key, and no license: entry in the tags. The page still said "No model card." The model had a new owner name and the same absence of terms.
Two things in that organization made it easy to get confused. The organization was small and listed no contact address, and another model in the same organization did carry an Apache-2.0 tag. "This organization publishes Apache-licensed models" and "this specific model has no license" were both true, and the first one did nothing to change the second.
What I did about it
I wrote the depth model down as a red flag, high priority, and drafted an inquiry to the maintainers about the model's license. The plan was explicit: until there was a clear answer, that project would stay out of anything I sold. As of the last entry in my project log, that inquiry was still an unsent draft.
The self-serve version of the product was frozen. There were two reasons, and I want to be honest that the license was only one of them: the other was that free open-source tools already covered most of the value I'd planned to charge for. What made the license problem hard to wave away was where it sat: the model with no license was one of the two that the core feature loads by default. Swapping it for a differently licensed depth model, or retraining one, went into my notes as alternatives, but I didn't pursue either.
I've also left the optional parts of that project alone. In July I also couldn't determine a license for two more models used only in its data-preparation pipeline. I confirmed from the code that the inference path I cared about never loads them, wrote that down, and noted that if anyone ever wants those features, the same question has to be asked first. In the November re-check, one of the two declared a license and the other still declared none.
The check, as a script
Here's the check I now do by hand, written up as a small script for this post. I ran it against a few public models while writing this, including one whose old name redirects to a new organization, to make sure the redirect line actually shows up. It asks the Hugging Face API for a model's metadata, reports whether the path redirected, and prints every place a license could be declared — so that "missing" shows up as missing instead of as silence.
import sys
import requests
def check_model(repo_id: str) -> None:
url = f"https://huggingface.co/api/models/{repo_id}"
resp = requests.get(url, timeout=30)
# requests follows redirects by default; history keeps the hops
for hop in resp.history:
print(f" redirect: {hop.status_code} -> {hop.headers.get('location')}")
print(f" final status: {resp.status_code}")
if resp.status_code != 200:
print(" could not read metadata; treat license as UNKNOWN")
return
info = resp.json()
card = info.get("cardData") or {}
card_license = card.get("license")
tag_licenses = [t for t in info.get("tags", []) if t.startswith("license:")]
base_models = [t for t in info.get("tags", []) if t.startswith("base_model:")]
print(f" cardData present: {bool(info.get('cardData'))}")
print(f" cardData.license: {card_license!r}")
print(f" license tags: {tag_licenses or 'NONE'}")
print(f" base_model tags: {base_models or 'none declared'}")
if not card_license and not tag_licenses:
print(" FLAG: no license declared in metadata -> ask before using")
if __name__ == "__main__":
for repo in sys.argv[1:]:
print(repo)
check_model(repo)
A few notes on what this does and doesn't do:
- It reads metadata, not law. A license tag here is what the uploader typed. It tells you what was claimed, not whether the claim survives the base model's terms.
- The redirect check matters. If the path redirects, the model has moved, and the account you'd ask for permission may be different from the one you started with.
-
base_modeltags are optional. If none are declared, that's not evidence there is no base model. In my case I found the lineage in the training config in the code repository, which is why the next step is to go read it. -
Run it on the defaults in the code, not the models in the README. The models that matter are the ones the inference script actually loads. Start from the
from_pretrainedcalls and the argument defaults, and work outward.
The checklist I use now
When I evaluate an ML project for anything commercial, I go through it in this order:
- Find what actually runs. Read the inference entry point. List every model ID it loads, including argument defaults and anything downloaded from a URL. That list, not the README, is your dependency list for weights.
- Check code dependencies separately from weights. A permissive top-level license covers the code next to it. It says nothing about the weights the code downloads.
- Look up each model's license at the source, by API if you can. Note when there's no license at all, and record it as "not usable until permission is granted," not as "unrestricted."
- Trace the lineage. For fine-tuned models, find the base model — in the training configs if the model card doesn't say — and check its license. Write down when the fine-tune's tag and the base model's license disagree.
- Check whether the model has moved. Look at raw response headers for redirects. Don't trust a tool's summary of "is there a redirect"; it may be describing the page at the end of the redirect.
- Separate the core path from the optional one. If unlicensed models are only used by features you don't ship, confirm that from the code and write down that the question reopens if those features ever ship.
- Decide what happens until you have an answer. In my case, the rule was that the project stayed out of anything sold until the license question was explicitly resolved.
What I'd generalize from this
The pattern underneath both mistakes I almost made is the same one: a summary was answering a different question from the one I asked.
The top-level LICENSE file answered "what are the terms for this code?" I was asking "what are the terms for what this code produces?" The model hub's license tag answered "what did the uploader declare?" I was asking "what am I actually allowed to do?" The web tool answered "what does the final page say?" I was asking "did the request get redirected?"
None of those sources were wrong about their own question. Each was a confident, tidy answer that fit just well enough to stop me looking further. The fix, every time, was to go one layer closer to the raw thing: the from_pretrained defaults instead of the README, the training config instead of the tag, the response headers instead of the page summary, the API JSON instead of the rendered model page.
If you're building on open-source ML, the check is cheap and the failure mode is expensive. It's a lot better to find the missing license before you've built the product around it than after a customer's legal team finds it for you.
I write about things that went wrong while building software, mostly as a solo developer. If you've dealt with a model that had no license, or found a better way to trace fine-tune lineage, I'd like to hear how you handled it.
來源:DEV Community · dev.to