MCPcopy Index your code
hub / github.com/modelscope/modelscope / from_pretrained

Method from_pretrained

modelscope/preprocessors/base.py:206–345  ·  view source on GitHub ↗

Instantiate a preprocessor from local directory or remote model repo. Note that when loading from remote, the model revision can be specified. Args: model_name_or_path(str): A model dir or a model id used to load the preprocessor out. revision(str, `optional`

(cls,
                        model_name_or_path: str,
                        revision: Optional[str] = DEFAULT_MODEL_REVISION,
                        cfg_dict: Config = None,
                        preprocessor_mode=ModeKeys.INFERENCE,
                        trust_remote_code=False,
                        **kwargs)

Source from the content-addressed store, hash-verified

204
205 @classmethod
206 def from_pretrained(cls,
207 model_name_or_path: str,
208 revision: Optional[str] = DEFAULT_MODEL_REVISION,
209 cfg_dict: Config = None,
210 preprocessor_mode=ModeKeys.INFERENCE,
211 trust_remote_code=False,
212 **kwargs):
213 """Instantiate a preprocessor from local directory or remote model repo. Note
214 that when loading from remote, the model revision can be specified.
215
216 Args:
217 model_name_or_path(str): A model dir or a model id used to load the preprocessor out.
218 revision(str, `optional`): The revision used when the model_name_or_path is
219 a model id of the remote hub. default `master`.
220 cfg_dict(Config, `optional`): An optional config. If provided, it will replace
221 the config read out of the `model_name_or_path`
222 preprocessor_mode(str, `optional`): Specify the working mode of the preprocessor, can be `train`, `eval`,
223 or `inference`. Default value `inference`.
224 The preprocessor field in the config may contain two sub preprocessors:
225 >>> {
226 >>> "train": {
227 >>> "type": "some-train-preprocessor"
228 >>> },
229 >>> "val": {
230 >>> "type": "some-eval-preprocessor"
231 >>> }
232 >>> }
233 In this scenario, the `train` preprocessor will be loaded in the `train` mode, the `val` preprocessor
234 will be loaded in the `eval` or `inference` mode. The `mode` field in the preprocessor class
235 will be assigned in all the modes.
236 Or just one:
237 >>> {
238 >>> "type": "some-train-preprocessor"
239 >>> }
240 In this scenario, the sole preprocessor will be loaded in all the modes,
241 and the `mode` field in the preprocessor class will be assigned.
242
243 **kwargs:
244 task(str, `optional`): The `Tasks` enumeration value to replace the task value
245 read out of config in the `model_name_or_path`.
246 This is useful when the preprocessor does not have a `type` field and the task to be used is not
247 equal to the task of which the model is saved.
248 Other kwargs will be directly fed into the preprocessor, to replace the default configs.
249
250 Returns:
251 The preprocessor instance.
252
253 Examples:
254 >>> from modelscope.preprocessors import Preprocessor
255 >>> Preprocessor.from_pretrained('damo/nlp_debertav2_fill-mask_chinese-base')
256
257 """
258 if not os.path.exists(model_name_or_path):
259 model_dir = snapshot_download(
260 model_name_or_path,
261 revision=revision,
262 user_agent={Invoke.KEY: Invoke.PREPROCESSOR},
263 ignore_file_pattern=[

Callers 15

tokenizerMethod · 0.45
__init__Method · 0.45
tokenizerMethod · 0.45
tokenizerMethod · 0.45
__init__Method · 0.45
load_by_model_idMethod · 0.45
__init__Method · 0.45
__init__Method · 0.45
build_tokenizerMethod · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 8

snapshot_downloadFunction · 0.90
read_configFunction · 0.90
ConfigDictClass · 0.90
build_preprocessorFunction · 0.85
find_field_by_taskMethod · 0.80
infoMethod · 0.80
existsMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected