@@ -2550,8 +2550,11 @@ def is_nv_fp(backend):
2550
2550
2551
2551
2552
2552
def is_wfp8afp8 (ar ):
2553
- if ("fp8" in ar .act_data_type or ("fp" in ar .act_data_type and ar .act_bits == 8 )) and (
2554
- "fp8" in ar .data_type or ("fp" in ar .data_type and ar .bits == 8 )
2553
+ if (
2554
+ ("fp8" in ar .act_data_type or ("fp" in ar .act_data_type and ar .act_bits == 8 ))
2555
+ and ("fp8" in ar .data_type or ("fp" in ar .data_type and ar .bits == 8 ))
2556
+ and is_standard_fp (ar .act_data_type )
2557
+ and is_standard_fp (ar .data_type )
2555
2558
):
2556
2559
return True
2557
2560
else :
@@ -2677,3 +2680,35 @@ def _get_packing_device(device: str | torch.device | None = "auto") -> torch.dev
2677
2680
raise ValueError (f"Invalid device string: { device } " ) from e
2678
2681
2679
2682
raise TypeError (f"Unsupported device type: { type (device )} ({ device } )" )
2683
+
2684
+
2685
+ # Adapted from https://github.com/vllm-project/llm-compressor/blob/
2686
+ # 5b3ddff74cae9651f24bef15d3255c4ee053fc60/src/llmcompressor/pytorch/model_load/helpers.py#L144
2687
+ def copy_python_files_from_model_cache (model , save_path : str ):
2688
+ config = model .config
2689
+ cache_path = None
2690
+ if hasattr (config , "_name_or_path" ):
2691
+ import os
2692
+ import shutil
2693
+
2694
+ from huggingface_hub import hf_hub_download
2695
+ from transformers import TRANSFORMERS_CACHE
2696
+ from transformers .utils import http_user_agent
2697
+
2698
+ cache_path = config ._name_or_path
2699
+ if not os .path .exists (cache_path ):
2700
+ user_agent = http_user_agent ()
2701
+ config_file_path = hf_hub_download (
2702
+ repo_id = cache_path ,
2703
+ filename = "config.json" ,
2704
+ cache_dir = TRANSFORMERS_CACHE ,
2705
+ force_download = False ,
2706
+ user_agent = user_agent ,
2707
+ )
2708
+ cache_path = os .path .sep .join (config_file_path .split (os .path .sep )[:- 1 ])
2709
+
2710
+ for file in os .listdir (cache_path ):
2711
+ full_file_name = os .path .join (cache_path , file )
2712
+ if file .endswith (".py" ) and os .path .isfile (full_file_name ):
2713
+ logger .debug (f"Transferring { full_file_name } to { save_path } " )
2714
+ shutil .copy (full_file_name , save_path )
0 commit comments