fix: remove trust_remote_code setting

This improves security when running Heretic with an untrusted config file. The prompt is now always shown.

This is NOT a breaking change, because we currently ignore values for unknown settings, so existing configs continue to work.
This commit is contained in:
Philipp Emanuel Weidmann
2026-05-29 11:38:04 +05:30
parent 223d0f88bf
commit 96e4d2b381
3 changed files with 16 additions and 18 deletions
-7
View File
@@ -170,13 +170,6 @@ class Settings(BaseSettings):
),
)
trust_remote_code: bool | None = Field(
default=None,
description="Whether to trust remote code when loading the model.",
# For security reasons, we don't store this setting.
exclude=True,
)
batch_size: int = Field(
default=0, # auto
description="Number of input sequences to process in parallel (0 = auto).",
+3 -1
View File
@@ -117,7 +117,9 @@ def obtain_merge_strategy(settings: Settings, model: Model) -> str | None:
settings.model,
device_map="meta",
torch_dtype=torch.bfloat16,
trust_remote_code=model.trusted_models.get(settings.model),
trust_remote_code=True
if settings.model in model.trusted_models
else None,
**model.revision_kwargs,
)
footprint_bytes = meta_model.get_memory_footprint()
+13 -10
View File
@@ -71,7 +71,6 @@ class Model:
self.tokenizer = AutoTokenizer.from_pretrained(
settings.model,
trust_remote_code=settings.trust_remote_code,
**self.revision_kwargs,
)
@@ -90,10 +89,8 @@ class Model:
if settings.max_memory
else None
)
self.trusted_models = {settings.model: settings.trust_remote_code}
if self.settings.evaluate_model is not None:
self.trusted_models[settings.evaluate_model] = settings.trust_remote_code
self.trusted_models = set()
for dtype in settings.dtypes:
print(f"* Trying dtype [bold]{dtype}[/]...")
@@ -112,15 +109,17 @@ class Model:
dtype=dtype,
device_map=settings.device_map,
max_memory=self.max_memory,
trust_remote_code=self.trusted_models.get(settings.model),
trust_remote_code=True
if settings.model in self.trusted_models
else None,
**self.revision_kwargs,
**extra_kwargs,
)
# If we reach this point and the model requires trust_remote_code,
# either the user accepted, or settings.trust_remote_code is True.
if self.trusted_models.get(settings.model) is None:
self.trusted_models[settings.model] = True
# the user must have agreed when prompted to execute remote code,
# because from_pretrained raises an exception otherwise.
self.trusted_models.add(settings.model)
# A test run can reveal dtype-related problems such as the infamous
# "RuntimeError: probability tensor contains either `inf`, `nan` or element < 0"
@@ -264,7 +263,9 @@ class Model:
self.settings.model,
torch_dtype=self.model.dtype,
device_map="cpu",
trust_remote_code=self.trusted_models.get(self.settings.model),
trust_remote_code=True
if self.settings.model in self.trusted_models
else None,
**self.revision_kwargs,
)
@@ -326,7 +327,9 @@ class Model:
dtype=dtype,
device_map=self.settings.device_map,
max_memory=self.max_memory,
trust_remote_code=self.trusted_models.get(self.settings.model),
trust_remote_code=True
if self.settings.model in self.trusted_models
else None,
**self.revision_kwargs,
**extra_kwargs,
)