config.py 900 B

12345678910111213141516171819202122
  1. from typing import Optional
  2. from transformers import AutoConfig, PretrainedConfig
  3. def get_config(model: str,
  4. trust_remote_code: bool,
  5. revision: Optional[str] = None) -> PretrainedConfig:
  6. try:
  7. config = AutoConfig.from_pretrained(
  8. model, trust_remote_code=trust_remote_code, revision=revision)
  9. except ValueError as e:
  10. if (not trust_remote_code and
  11. "requires you to execute the configuration file" in str(e)):
  12. err_msg = (
  13. "Failed to load the model config. If the model uses custom "
  14. "code not yet available in HF transformers library, consider "
  15. "setting `trust_remote_code=True` in LLM or using the "
  16. "`--trust-remote-code` flag in the CLI.")
  17. raise RuntimeError(err_msg) from e
  18. else:
  19. raise e
  20. return config