proc_conf_oss.py 875 B

1234567891011121314151617181920212223242526272829303132333435
  1. from pathlib import Path
  2. import torch
  3. import yaml
  4. class NoAliasSafeDumper(yaml.SafeDumper):
  5. # Disable anchor/alias in yaml because looks ugly
  6. def ignore_aliases(self, data):
  7. return True
  8. def yaml_no_alias_safe_dump(data, stream=None, **kwargs):
  9. """Safe-dump in yaml with no anchor/alias"""
  10. return yaml.dump(
  11. data, stream, allow_unicode=True, Dumper=NoAliasSafeDumper, **kwargs
  12. )
  13. def gen_conf(file, out_dir):
  14. conf = torch.load(file)["config"]
  15. conf["oss_bucket"] = "null"
  16. print(conf)
  17. output_dir = Path(out_dir)
  18. output_dir.mkdir(parents=True, exist_ok=True)
  19. with (output_dir / "config.yaml").open("w", encoding="utf-8") as f:
  20. yaml_no_alias_safe_dump(conf, f, indent=4, sort_keys=False)
  21. if __name__ == "__main__":
  22. import sys
  23. in_f = sys.argv[1]
  24. out_f = sys.argv[2]
  25. gen_conf(in_f, out_f)