| 385 | reset_config_value("ROPE_THETA", 10000) |
| 386 | |
| 387 | def read_model_config(self): |
| 388 | config_path = os.path.join(self.model, "config.json") |
| 389 | if os.path.exists(config_path): |
| 390 | with open(config_path, "r", encoding="utf-8") as f: |
| 391 | raw_cfg = json.load(f) |
| 392 | if "text_config" in raw_cfg and isinstance(raw_cfg["text_config"], dict): |
| 393 | text_cfg = raw_cfg.pop("text_config") |
| 394 | for k, v in text_cfg.items(): |
| 395 | if k not in raw_cfg: |
| 396 | raw_cfg[k] = v |
| 397 | self.model_config = raw_cfg |
| 398 | if "torch_dtype" in self.model_config and "dtype" in self.model_config: |
| 399 | raise ValueError( |
| 400 | "Only one of 'torch_dtype' or 'dtype' should be present in config.json. " |
| 401 | "Found both, which indicates an ambiguous model format. " |
| 402 | "Please ensure your config.json contains only one dtype field." |
| 403 | ) |
| 404 | elif "torch_dtype" in self.model_config: |
| 405 | self.model_format = "torch" |
| 406 | logger.info("The model format is Hugging Face Torch") |
| 407 | elif "dtype" in self.model_config: |
| 408 | # https://github.com/huggingface/transformers/releases/tag/v4.56.0 Transformers 4.56.0 version deprecated torch_dtype |
| 409 | if "transformers_version" in self.model_config and parse_version( |
| 410 | self.model_config["transformers_version"] |
| 411 | ) > parse_version("4.56.0"): |
| 412 | self.model_format = "torch" |
| 413 | logger.info("The model format is Hugging Face Torch") |
| 414 | else: |
| 415 | self.model_format = "paddle" |
| 416 | logger.info("The model format is Paddle") |
| 417 | elif ( |
| 418 | "quantization_config" in self.model_config |
| 419 | and "quant_method" in self.model_config["quantization_config"] |
| 420 | and "mxfp4" == self.model_config["quantization_config"]["quant_method"] |
| 421 | ): |
| 422 | self.model_format = "torch" |
| 423 | logger.info("The model format is Hugging Face") |
| 424 | else: |
| 425 | raise ValueError( |
| 426 | "Unknown model format. Please ensure your config.json contains " |
| 427 | "either 'torch_dtype' (for Hugging Face models) or 'dtype' (for Paddle models) field. " |
| 428 | f"Config file path: {config_path}" |
| 429 | ) |
| 430 | |
| 431 | def _get_default_runner_type( |
| 432 | self, |