test_ds_config.py 1012 B

1234567891011121314151617181920212223242526272829303132333435
  1. import pytest
  2. import os
  3. import json
  4. from deepspeed.runtime import config as ds_config
  5. def test_only_required_fields(tmpdir):
  6. '''Ensure that config containing only the required fields is accepted. '''
  7. cfg_json = tmpdir.mkdir('ds_config_unit_test').join('minimal.json')
  8. with open(cfg_json, 'w') as f:
  9. required_fields = {'train_batch_size': 64}
  10. json.dump(required_fields, f)
  11. run_cfg = ds_config.DeepSpeedConfig(cfg_json)
  12. assert run_cfg is not None
  13. assert run_cfg.train_batch_size == 64
  14. assert run_cfg.train_micro_batch_size_per_gpu == 64
  15. assert run_cfg.gradient_accumulation_steps == 1
  16. def test_config_duplicate_key(tmpdir):
  17. config_dict = '''
  18. {
  19. "train_batch_size": 24,
  20. "train_batch_size": 24,
  21. }
  22. '''
  23. config_path = os.path.join(tmpdir, 'temp_config.json')
  24. with open(config_path, 'w') as jf:
  25. jf.write("%s" % config_dict)
  26. with pytest.raises(ValueError):
  27. run_cfg = ds_config.DeepSpeedConfig(config_path)