mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
fix trainer + trust_remote_code (#1713)
This commit is contained in:
@@ -14,7 +14,8 @@ from modelscope.utils.config import Config, ConfigDict
|
||||
from modelscope.utils.constant import DEFAULT_MODEL_REVISION, Invoke, ModelFile
|
||||
from modelscope.utils.device import verify_device
|
||||
from modelscope.utils.logger import get_logger
|
||||
from modelscope.utils.plugins import (register_modelhub_repo,
|
||||
from modelscope.utils.plugins import (filter_plugin_in_whitelist,
|
||||
register_modelhub_repo,
|
||||
register_plugins_repo)
|
||||
|
||||
logger = get_logger()
|
||||
@@ -190,7 +191,7 @@ class Model(ABC):
|
||||
|
||||
# Security check: Only allow execution of remote code or plugins if trust_remote_code is True
|
||||
plugins = cfg.safe_get('plugins')
|
||||
if plugins and not trust_remote_code:
|
||||
if filter_plugin_in_whitelist(plugins) and not trust_remote_code:
|
||||
raise RuntimeError(
|
||||
'Detected plugins field in the model configuration file, but '
|
||||
'trust_remote_code=True was not explicitly set.\n'
|
||||
|
||||
@@ -135,6 +135,7 @@ class EpochBasedTrainer(BaseTrainer):
|
||||
self._inner_iter = 0
|
||||
self._stop_training = False
|
||||
self._compile = kwargs.get('compile', False)
|
||||
self.trust_remote_code = kwargs.get('trust_remote_code', False)
|
||||
|
||||
self.train_dataloader = None
|
||||
self.eval_dataloader = None
|
||||
@@ -814,7 +815,10 @@ class EpochBasedTrainer(BaseTrainer):
|
||||
override this method in a subclass.
|
||||
|
||||
"""
|
||||
model = Model.from_pretrained(self.model_dir, cfg_dict=self.cfg)
|
||||
model = Model.from_pretrained(
|
||||
self.model_dir,
|
||||
cfg_dict=self.cfg,
|
||||
trust_remote_code=self.trust_remote_code)
|
||||
if not isinstance(model, nn.Module) and hasattr(model, 'model'):
|
||||
return model.model
|
||||
elif isinstance(model, nn.Module):
|
||||
|
||||
Reference in New Issue
Block a user