MCPcopy Create free account
hub / github.com/modelscope/modelscope / dump

Method dump

modelscope/utils/config.py:422–458  ·  view source on GitHub ↗

Dumps config into a file or returns a string representation of the config. If a file argument is given, saves the config to that file using the format defined by the file argument extension. Otherwise, returns a string representing the config. The formatting of

(self, file: str = None)

Source from the content-addressed store, hash-verified

420 return default
421
422 def dump(self, file: str = None):
423 """Dumps config into a file or returns a string representation of the
424 config.
425
426 If a file argument is given, saves the config to that file using the
427 format defined by the file argument extension.
428
429 Otherwise, returns a string representing the config. The formatting of
430 this returned string is defined by the extension of `self.filename`. If
431 `self.filename` is not defined, returns a string representation of a
432 dict (lowercased and using ' for strings).
433
434 Examples:
435 >>> cfg_dict = dict(item1=[1, 2], item2=dict(a=0),
436 ... item3=True, item4='test')
437 >>> cfg = Config(cfg_dict=cfg_dict)
438 >>> dump_file = "a.py"
439 >>> cfg.dump(dump_file)
440
441 Args:
442 file (str, optional): Path of the output file where the config
443 will be dumped. Defaults to None.
444 """
445 from modelscope.fileio import dump
446 cfg_dict = super(Config, self).__getattribute__('_cfg_dict').to_dict()
447 if file is None:
448 if self.filename is None or self.filename.endswith('.py'):
449 return self.pretty_text
450 else:
451 file_format = self.filename.split('.')[-1]
452 return dump(cfg_dict, file_format=file_format)
453 elif file.endswith('.py'):
454 with open(file, 'w', encoding='utf-8') as f:
455 f.write(self.pretty_text)
456 else:
457 file_format = file.split('.')[-1]
458 return dump(cfg_dict, file=file, file_format=file_format)
459
460 def merge_from_dict(self, options, allow_list_keys=True, force=True):
461 """Merge dict into cfg_dict.

Callers 15

train_workerFunction · 0.95
_check_pickleableFunction · 0.45
monitor_module_trainMethod · 0.45
write_dictFunction · 0.45
saveMethod · 0.45
save_model_metaMethod · 0.45
save_indexMethod · 0.45
forwardMethod · 0.45
collect_results_cpuFunction · 0.45

Calls 4

dumpFunction · 0.90
__getattribute__Method · 0.80
to_dictMethod · 0.45
writeMethod · 0.45

Tested by 15

train_workerFunction · 0.76
monitor_module_trainMethod · 0.36
test_dumpMethod · 0.36
prepare_dirMethod · 0.36
prepare_dirMethod · 0.36
setUpMethod · 0.36
setUpMethod · 0.36
test_trainer_stdMethod · 0.36
test_train_0Method · 0.36
test_train_1Method · 0.36