mirror of
https://github.com/p-e-w/heretic.git
synced 2026-09-26 05:51:25 -07:00
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:
@@ -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(
|
batch_size: int = Field(
|
||||||
default=0, # auto
|
default=0, # auto
|
||||||
description="Number of input sequences to process in parallel (0 = auto).",
|
description="Number of input sequences to process in parallel (0 = auto).",
|
||||||
|
|||||||
+3
-1
@@ -117,7 +117,9 @@ def obtain_merge_strategy(settings: Settings, model: Model) -> str | None:
|
|||||||
settings.model,
|
settings.model,
|
||||||
device_map="meta",
|
device_map="meta",
|
||||||
torch_dtype=torch.bfloat16,
|
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,
|
**model.revision_kwargs,
|
||||||
)
|
)
|
||||||
footprint_bytes = meta_model.get_memory_footprint()
|
footprint_bytes = meta_model.get_memory_footprint()
|
||||||
|
|||||||
+13
-10
@@ -71,7 +71,6 @@ class Model:
|
|||||||
|
|
||||||
self.tokenizer = AutoTokenizer.from_pretrained(
|
self.tokenizer = AutoTokenizer.from_pretrained(
|
||||||
settings.model,
|
settings.model,
|
||||||
trust_remote_code=settings.trust_remote_code,
|
|
||||||
**self.revision_kwargs,
|
**self.revision_kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -90,10 +89,8 @@ class Model:
|
|||||||
if settings.max_memory
|
if settings.max_memory
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
self.trusted_models = {settings.model: settings.trust_remote_code}
|
|
||||||
|
|
||||||
if self.settings.evaluate_model is not None:
|
self.trusted_models = set()
|
||||||
self.trusted_models[settings.evaluate_model] = settings.trust_remote_code
|
|
||||||
|
|
||||||
for dtype in settings.dtypes:
|
for dtype in settings.dtypes:
|
||||||
print(f"* Trying dtype [bold]{dtype}[/]...")
|
print(f"* Trying dtype [bold]{dtype}[/]...")
|
||||||
@@ -112,15 +109,17 @@ class Model:
|
|||||||
dtype=dtype,
|
dtype=dtype,
|
||||||
device_map=settings.device_map,
|
device_map=settings.device_map,
|
||||||
max_memory=self.max_memory,
|
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,
|
**self.revision_kwargs,
|
||||||
**extra_kwargs,
|
**extra_kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
# If we reach this point and the model requires trust_remote_code,
|
# If we reach this point and the model requires trust_remote_code,
|
||||||
# either the user accepted, or settings.trust_remote_code is True.
|
# the user must have agreed when prompted to execute remote code,
|
||||||
if self.trusted_models.get(settings.model) is None:
|
# because from_pretrained raises an exception otherwise.
|
||||||
self.trusted_models[settings.model] = True
|
self.trusted_models.add(settings.model)
|
||||||
|
|
||||||
# A test run can reveal dtype-related problems such as the infamous
|
# A test run can reveal dtype-related problems such as the infamous
|
||||||
# "RuntimeError: probability tensor contains either `inf`, `nan` or element < 0"
|
# "RuntimeError: probability tensor contains either `inf`, `nan` or element < 0"
|
||||||
@@ -264,7 +263,9 @@ class Model:
|
|||||||
self.settings.model,
|
self.settings.model,
|
||||||
torch_dtype=self.model.dtype,
|
torch_dtype=self.model.dtype,
|
||||||
device_map="cpu",
|
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,
|
**self.revision_kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -326,7 +327,9 @@ class Model:
|
|||||||
dtype=dtype,
|
dtype=dtype,
|
||||||
device_map=self.settings.device_map,
|
device_map=self.settings.device_map,
|
||||||
max_memory=self.max_memory,
|
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,
|
**self.revision_kwargs,
|
||||||
**extra_kwargs,
|
**extra_kwargs,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user