Conversation
Hotragn
force-pushed
the
fix/trust-remote-code-default-293
branch
from
July 29, 2026 18:16
476a89d to
6553cf5
Compare
Author
|
Rebased onto v3.1.0 — the only conflict was the Still relevant on v3.1.0: |
AutoModel.get_module_class (config load) and the base/MLX tokenizer loads hard-coded trust_remote_code=True, so a normal AirLLM load of an arbitrary Hugging Face repo id would execute Python shipped in that repo -- even for standard architectures that don't need it. AirLLMBaseModel already loads the model config/weights with trust_remote_code=False and only falls back to True when transformers can't parse the model natively; this makes every other load boundary consistent with that. - Add load_prefer_no_remote_code() helper: try trust_remote_code=False, fall back to True only if the native load raises. - Use it for the config load in AutoModel.get_module_class, the tokenizer load in AirLLMBaseModel, and the config + tokenizer loads in the MLX path. - Standard models never trigger remote code now; models that genuinely need it (ChatGLM, Baichuan, some Qwen) still work via the fallback. No API change. - Add offline unit tests for the helper and the get_module_class behavior. Addresses lyogavin#293.
Hotragn
force-pushed
the
fix/trust-remote-code-default-293
branch
from
September 5, 2026 17:10
6553cf5 to
697aba6
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stop hard-coding
trust_remote_code=Trueat the config and tokenizer load boundaries. Instead prefer transformers' native implementation and only fall back to the repo's remote code when it's actually required.Addresses #293. (Left as "addresses" rather than "fixes" — see Scope below.)
Why
AirLLMBaseModelalready loads the model config/weights this way — it triestrust_remote_code=Falseand only falls back toTruewhen transformers can't parse the model natively (base.py:113–120, 185/194). But two other load boundaries still passedtrust_remote_code=Trueunconditionally:AutoModel.get_module_class()— the config load, which runs first, before the model is even constructed (auto_model.py).AirLLMBaseModel.get_tokenizer()and the MLX path's config + tokenizer loads.Since AirLLM's advertised entry point is an arbitrary Hugging Face repo id (
AutoModel.from_pretrained("some/repo")), those unconditionalTrues mean a normal load of a standard architecture (Llama, Qwen3, Mistral, …) would still execute Python shipped in the repo, with no way for the caller to stay on transformers' default remote-code boundary.This PR makes every load boundary consistent with the pattern the model loading already uses.
Changes
load_prefer_no_remote_code(loader, *args, **kwargs)inutils.py: try the loader withtrust_remote_code=False, fall back totrust_remote_code=Trueonly if the native load raises.AutoModel.get_module_class, the tokenizer load inAirLLMBaseModel, and the config + tokenizer loads inAirLLMLlamaMlx.Behavior: standard models no longer trigger remote-code execution during config/tokenizer loading. Models that genuinely ship custom code (ChatGLM, Baichuan, some Qwen) still work because the fallback re-loads with
trust_remote_code=True. No API change, no new required arguments.Scope / what this deliberately does not do
This mirrors your existing auto-fallback approach rather than adding a new public
trust_remote_code=parameter. The auto-fallback is a strict improvement (the common case stops running remote code) but it does not give a hard opt-out: a repo that genuinely requires remote code will still run it via the fallback. A follow-up could add an explicittrust_remote_code: Optional[bool] = Nonekwarg (None = current auto behavior,False= hard refuse,True= force) for callers who want a guarantee. I left that out here to keep the change minimal and consistent with the current design — happy to add it if you'd prefer. That's also why this says "Addresses" rather than "Fixes" #293, so the issue stays open for that decision.Testing
python -m pytest air_llm/tests/test_trust_remote_code.py— 5 offline tests (no network, no GPU), all pass:trust_remote_code=Falseand does not retry when the native load succeedsTruewhen theFalseload raisestoken)get_module_classloads a standard arch's config withtrust_remote_code=Falseonlyget_module_classfalls back toTruefor a custom arch (e.g. ChatGLM) and still resolves the right classNote: the MLX path is changed identically but I couldn't run it locally (no Apple silicon) — it's a mechanical mirror of the generic path using the same tested helper.