`trust_remote_code=True` is hard-coded in the Hugging Face and vLLM wrappers and cannot be turned off
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 50/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- huggingface, python
- Domain
- machine-learning, security
Research direction
The hard-coded trust_remote_code=True sits in lagent/llms/huggingface.py (tokenizer and model from_pretrained calls), lagent/llms/vllm_wrapper.py (LLM(...) and AsyncEngineArgs(...)), and lagent/actions/web_visitor.py (tokenizer load). Start by reading how model_kwargs and tokenizer_kwargs are merged into those calls, since that is where the duplicate-keyword TypeError comes from. Done means both parameters are exposed on the four classes and forwarded to every call, and the default stays True. The design of the parameter names and defaults should be confirmed with maintainers first.
Written by the indexing model from the issue text.
Description
The local model wrappers always pass trust_remote_code=True, with no way for the caller to disable it and no way to pin a Hub revision:
- lagent/llms/huggingface.py#L77-L80:
AutoTokenizer.from_pretrained(..., trust_remote_code=True, **tokenizer_kwargs) - lagent/llms/huggingface.py#L107-L108 and #L299-L300:
AutoModel/AutoModelForCausalLM.from_pretrained(path, trust_remote_code=True, **model_kwargs) - lagent/llms/vllm_wrapper.py#L38-L42
LLM(model=self.path, trust_remote_code=True, ...), and #L110-L114:AsyncEngineArgs(model=self.path, trust_remote_code=True, ...) - lagent/actions/web_visitor.py#L114-L116:
AutoTokenizer.from_pretrained(tokenizer_path, trust_remote_code=True)
Why it matters
- With
trust_remote_code=True, Transformers and vLLM import and run the Python files shipped in the model repo. Because norevisionis pinned, that code is whatever the Hub repo's default branch holds at load time, so an update or a compromised upstream repo runs new code in the agent process. - Callers cannot opt out: passing
trust_remote_code=Falseinmodel_kwargs/tokenizer_kwargsraisesTypeError: got multiple values for keyword argument 'trust_remote_code'. That makes the wrappers unusable in setups that require it to be off, even for models that do not need custom code.
I understand trust_remote_code was added on purpose (#49, #50) so that InternLM and Qwen checkpoints load out of the box, so this is not a request to remove it.
Suggested fix
- Add
trust_remote_code: bool = True(keeping today's default) andrevision: Optional[str] = Noneparameters toHFTransformer,VllmModel,AsyncVllmModelandWebVisitor, and forward both to everyfrom_pretrained/LLM(...)call instead of the hard-coded keyword. - Document that a commit hash for
revisionis recommended whenevertrust_remote_codeis on.
Found with lacan-scan v7.6.4 (rule AIS203), checked by hand.
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 249
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from InternLM/lagent
-
OpenAI shuts down gpt-3.5-turbo and gpt-4o-2024-05-13 on 2026-10-23: default model_type values need updatingPossibly taken @qiyuhuating claimed this 53 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Techiebutler/freeframe#687 ·
Maintainers usually reply within 1 day
-
Parse truncated verbose GC logs up to the first XML errorPossibly taken A pull request linked to this issue is open or already merged. Openbug verbose GC
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
IBM/javacore-analyser#677 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 2 days
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
NousResearch/hermes-agent#163932 · 1 comment ·
Maintainers usually reply within 1 day
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's filePossibly taken @Beehtrix claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zilliztech/memsearch#907 · 1 comment ·
Maintainers usually reply within 1 day