4848# tests/regression/<TEST_NAME>/ will be loaded and compared to the current output.
4949#
5050# When implementing new tests, check the existing ones as well as the description in the docstring of RegressionTester.
51+ #
52+ # Note: For 4-bit tests using XPU (regardless of REGRESSION_CREATION_MODE), set `PEFT_USE_XPU=True` to enable the correct XPU path.
5153
5254import os
5355import shutil
8789HF_TOKEN = os .environ .get ("HF_TOKEN" )
8890# the repo has to be created manually once, it is not automatically created
8991HF_REPO = "peft-internal-testing/regression-tests"
92+ # note: For XPU devices, a separate regression test repository(for 4 bit) is used due to hardware and implementation
93+ # differences that can lead to different numerical results compared to CUDA-based devices.
94+ # See PR https://github.com/huggingface/peft/pull/2843
95+ HF_REPO_XPU = "Intel/peft-regression-tests"
96+ LORA_4BIT_FOLDER = "lora_opt-350m_bnb_4bit"
9097
9198
9299@pytest .fixture (scope = "session" , autouse = True )
@@ -96,17 +103,40 @@ def setup_tearndown():
96103
97104 # download regression artifacts from Hugging Face Hub at the start
98105 snapshot_download (repo_id = HF_REPO , local_dir = REGRESSION_DIR )
106+
107+ # WARNING: If running on XPU, LORA_4BIT_FOLDER artifacts are loaded from HF_REPO_XPU, which is outside of
108+ # peft direct control. The load_output function uses torch.load, which can execute arbitrary
109+ # code from pickle files. Users should be aware of this potential security risk.
110+ use_xpu = strtobool (os .environ .get ("PEFT_USE_XPU" , "False" )) and (infer_device () == "xpu" )
111+ if use_xpu :
112+ lora_4bit_folder_path = os .path .join (REGRESSION_DIR , LORA_4BIT_FOLDER )
113+ shutil .rmtree (lora_4bit_folder_path )
114+ snapshot_download (
115+ repo_id = HF_REPO_XPU ,
116+ local_dir = REGRESSION_DIR ,
117+ allow_patterns = [f"{ LORA_4BIT_FOLDER } /**" ],
118+ )
119+
99120 yield
100121
101122 # delete regression artifacts at the end of the test session; optionally, upload them first if in creation mode
102123 creation_mode = strtobool (os .environ .get ("REGRESSION_CREATION_MODE" , "False" ))
103124 if creation_mode :
104- # upload the regression directory to Hugging Face Hub, will overwrite by default
105- upload_folder (
106- repo_id = HF_REPO ,
107- folder_path = REGRESSION_DIR ,
108- token = HF_TOKEN ,
109- )
125+ if use_xpu :
126+ lora_4bit_folder_path = os .path .join (REGRESSION_DIR , LORA_4BIT_FOLDER )
127+ upload_folder (
128+ repo_id = HF_REPO_XPU ,
129+ folder_path = lora_4bit_folder_path ,
130+ path_in_repo = LORA_4BIT_FOLDER ,
131+ token = HF_TOKEN ,
132+ )
133+ else :
134+ # upload the regression directory to Hugging Face Hub, will overwrite by default
135+ upload_folder (
136+ repo_id = HF_REPO ,
137+ folder_path = REGRESSION_DIR ,
138+ token = HF_TOKEN ,
139+ )
110140
111141 shutil .rmtree (REGRESSION_DIR )
112142
@@ -637,7 +667,7 @@ def test_lora_4bit(self):
637667 init_lora_weights = False ,
638668 )
639669 model = get_peft_model (base_model , config )
640- self .assert_results_equal_or_store (model , "lora_opt-350m_bnb_4bit" )
670+ self .assert_results_equal_or_store (model , LORA_4BIT_FOLDER )
641671
642672 def test_adalora (self ):
643673 # TODO
0 commit comments