config.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. from typing import Optional
  2. from transformers import AutoConfig, PretrainedConfig
  3. from aphrodite.transformers_utils.configs import YiConfig
  4. _CONFIG_REGISTRY = {
  5. "yi": YiConfig,
  6. }
  7. def get_config(model: str,
  8. trust_remote_code: bool,
  9. revision: Optional[str] = None) -> PretrainedConfig:
  10. try:
  11. config = AutoConfig.from_pretrained(
  12. model, trust_remote_code=trust_remote_code, revision=revision)
  13. except ValueError as e:
  14. if (not trust_remote_code and
  15. "requires you to execute the configuration file" in str(e)):
  16. err_msg = (
  17. "Failed to load the model config. If the model is a custom "
  18. "model not yet available in the HuggingFace transformers "
  19. "library, consider setting `trust_remote_code=True` in LLM "
  20. "or using the `--trust-remote-code` flag in the CLI.")
  21. raise RuntimeError(err_msg) from e
  22. else:
  23. raise e
  24. if config.model_type in _CONFIG_REGISTRY:
  25. config_class = _CONFIG_REGISTRY[config.model_type]
  26. config = config_class.from_pretrained(model, revision=revision)
  27. return config