-
Notifications
You must be signed in to change notification settings - Fork 204
[FIX] add trust remote #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ def _init_length(self): | |
def _init_tokenizer(self): | ||
""" Initialize the tokenizer based on the provided tokenizer path.""" | ||
from modelscope import AutoTokenizer | ||
self.tokenizer = AutoTokenizer.from_pretrained(self.tokenizer_path) | ||
self.tokenizer = AutoTokenizer.from_pretrained(self.tokenizer_path, trust_remote_code=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
|
||
def load(self): | ||
"""Load dataset from local disk or remote.""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,9 @@ def load_model(self): | |
# model_pretrained_name_or_path = "yuvalkirstain/PickScore_v1" | ||
model_pretrained_name_or_path = 'AI-ModelScope/PickScore_v1' # modelscope model | ||
|
||
self.processor = AutoProcessor.from_pretrained(processor_name_or_path) | ||
self.model = AutoModel.from_pretrained(model_pretrained_name_or_path).eval().to(self.device) | ||
self.processor = AutoProcessor.from_pretrained(processor_name_or_path, trust_remote_code=True) | ||
self.model = AutoModel.from_pretrained(model_pretrained_name_or_path, | ||
trust_remote_code=True).eval().to(self.device) | ||
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
def load_images(self, image: List[str]) -> torch.Tensor: | ||
"""Load the image(s), and return a tensor (no preprocessing!!) put on self.device | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,9 @@ def load_model(self): | |
from ..utils import download_file | ||
|
||
# load tokenizer | ||
self.tokenizer = AutoTokenizer.from_pretrained('AI-ModelScope/bert-base-uncased', truncation_side='right') | ||
self.tokenizer = AutoTokenizer.from_pretrained( | ||
'AI-ModelScope/bert-base-uncased', truncation_side='right', trust_remote_code=True | ||
) | ||
Comment on lines
+40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
self.tokenizer.add_special_tokens({'bos_token': '[DEC]'}) | ||
# load model | ||
self.variant = FGA_BLIP2_MODELS[self.model_name]['variant'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
|
||
def init_tokenizer(): | ||
tokenizer = AutoTokenizer.from_pretrained('AI-ModelScope/bert-base-uncased') | ||
tokenizer = AutoTokenizer.from_pretrained('AI-ModelScope/bert-base-uncased', trust_remote_code=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
tokenizer.add_special_tokens({'bos_token': '[DEC]'}) | ||
tokenizer.add_special_tokens({'additional_special_tokens': ['[ENC]']}) | ||
tokenizer.enc_token_id = tokenizer.additional_special_tokens_ids[0] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ class BlipBase(BaseModel): | |
|
||
@classmethod | ||
def init_tokenizer(cls): | ||
tokenizer = AutoTokenizer.from_pretrained('AI-ModelScope/bert-base-uncased') | ||
tokenizer = AutoTokenizer.from_pretrained('AI-ModelScope/bert-base-uncased', trust_remote_code=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
tokenizer.add_special_tokens({'bos_token': '[DEC]'}) | ||
tokenizer.add_special_tokens({'additional_special_tokens': ['[ENC]']}) | ||
tokenizer.enc_token_id = tokenizer.additional_special_tokens_ids[0] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ def load_pretrained_model( | |
|
||
from ..utils import download_file | ||
|
||
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path, **tokenizer_dict) | ||
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path, trust_remote_code=True, **tokenizer_dict) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# tokenizer.pad_token = tokenizer.unk_token # could be redundant | ||
|
||
model_path = download_file(model_path, cache_dir=cache_dir) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ def __init__(self, param: Arguments): | |
super().__init__(param=param) | ||
if param.tokenizer_path is not None: | ||
from modelscope import AutoTokenizer | ||
self.tokenizer = AutoTokenizer.from_pretrained(param.tokenizer_path) | ||
self.tokenizer = AutoTokenizer.from_pretrained(param.tokenizer_path, trust_remote_code=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
else: | ||
self.tokenizer = None | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ def __init__(self, param: Arguments): | |
super().__init__(param=param) | ||
if param.tokenizer_path is not None: | ||
from modelscope import AutoTokenizer | ||
self.tokenizer = AutoTokenizer.from_pretrained(param.tokenizer_path) | ||
self.tokenizer = AutoTokenizer.from_pretrained(param.tokenizer_path, trust_remote_code=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
else: | ||
self.tokenizer = None | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ def __init__(self, report_path, tokenizer_path, model_name, dataset_name, subset | |
self.switch_tokens = ['alternatively', 'but wait', 'let me reconsider', 'another way', 'another approach', 'another method', 'another angle'] | ||
self.subset_dict = defaultdict(lambda: defaultdict(list)) | ||
self.think_end_token = '</think>' | ||
self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_path) | ||
self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_path, trust_remote_code=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
self.model_name = model_name | ||
self.dataset_name = dataset_name | ||
self.subsets = subsets | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
trust_remote_code=True
introduces a security risk, as it allows the execution of arbitrary code from the model hub. This could be exploited if a malicious model is used. It's recommended to make this behavior configurable and disabled by default, or at least add a clear warning to users about the potential risks.