update_config.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import yaml
  2. import argparse
  3. def update_dct(fin_configs, root):
  4. if root == {}:
  5. return {}
  6. for root_key, root_value in root.items():
  7. if not isinstance(root[root_key],dict):
  8. fin_configs[root_key] = root[root_key]
  9. else:
  10. result = update_dct(fin_configs[root_key], root[root_key])
  11. fin_configs[root_key] = result
  12. return fin_configs
  13. if __name__ == '__main__':
  14. parser = argparse.ArgumentParser(
  15. description="update configs",
  16. formatter_class=argparse.ArgumentDefaultsHelpFormatter,
  17. )
  18. parser.add_argument("--modelscope_config",
  19. type=str,
  20. help="modelscope config file")
  21. parser.add_argument("--finetune_config",
  22. type=str,
  23. help="finetune config file")
  24. parser.add_argument("--output_config",
  25. type=str,
  26. help="output config file")
  27. args = parser.parse_args()
  28. with open(args.modelscope_config) as f:
  29. modelscope_configs = yaml.safe_load(f)
  30. with open(args.finetune_config) as f:
  31. finetune_configs = yaml.safe_load(f)
  32. # update configs, e.g., lr, batch_size, ...
  33. modelscope_configs = update_dct(modelscope_configs, finetune_configs)
  34. with open(args.output_config, "w") as f:
  35. yaml.dump(modelscope_configs, f, indent=4)