Skip to content

feat: add trust_remote_code option to AutoDocumentEncoder/AutoQueryEncoder - #2645

Open
St4r4x wants to merge 1 commit into
castorini:masterfrom
St4r4x:feat/auto-encoder-trust-remote-code
Open

feat: add trust_remote_code option to AutoDocumentEncoder/AutoQueryEncoder#2645
St4r4x wants to merge 1 commit into
castorini:masterfrom
St4r4x:feat/auto-encoder-trust-remote-code

Conversation

@St4r4x

@St4r4x St4r4x commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Closes #2207

What

Adds an optional trust_remote_code: bool = False parameter to AutoDocumentEncoder and AutoQueryEncoder, threaded through to both AutoModel.from_pretrained() and the tokenizer loader. This lets models that require custom code on the Hub (e.g. nomic-ai/nomic-embed-text-v1, named in the issue) load without a blocking Y/N terminal prompt or needing to patch pyserini locally.

Scope

Scoped to the two Auto*Encoder classes named in the issue — these are the generic AutoModel.from_pretrained(...)-based wrappers. Model-specific encoders elsewhere in pyserini/encode/ (uniCOIL, SPLADE, DPR, etc.) load fixed, known architectures and don't need this knob.

load_auto_tokenizer() in _base.py already forwards **kwargs to AutoTokenizer.from_pretrained(), so no change was needed there beyond passing trust_remote_code through as a kwarg.

Default is False, so existing behavior is unchanged for everyone not opting in.

Not included (happy to add if wanted)

Didn't wire this into the CLI scripts (scripts/encode_queries.py etc.) — kept the diff to the encoder classes themselves per the issue's literal ask. Let me know if CLI flag support would be useful too.

Validation

Checked every call site of AutoDocumentEncoder/AutoQueryEncoder in the repo (tests, pyserini/search/faiss/_searcher.py, pyserini/encode/query.py, pyserini/demo/miracl.py, scripts/encode_queries.py) — all use keyword arguments after the first positional param, so this is fully backward compatible. Didn't run the full test suite (several of these tests download real models), but reviewed the changed logic against load_auto_tokenizer's existing kwarg-forwarding behavior to confirm the tokenizer side works without further changes.

…coder

Some HuggingFace models (e.g. nomic-ai/nomic-embed-text-v1) require
trust_remote_code=True to load, which previously required patching
pyserini or accepting a blocking Y/N terminal prompt every run.

Threads an optional trust_remote_code=False parameter through to both
AutoModel.from_pretrained() and load_auto_tokenizer() (which already
forwards **kwargs to AutoTokenizer.from_pretrained(), so no change
needed there). Defaults to False, matching current behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add trust_remote_code=True to load some specific models from huggingface

1 participant