File tree 2 files changed +24
-9
lines changed
2 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -71,12 +71,14 @@ def __init__(self, lora_layer: PeftLoraLayer):
71
71
self .base_layer = lora_layer .base_layer
72
72
self .r = lora_layer .r
73
73
self .lora_alpha = lora_layer .lora_alpha
74
- self .scaling = [
75
- torch .nn .Parameter (torch .as_tensor (scale ), requires_grad = False ).to (
76
- self .base_layer .weight .device
77
- )
78
- for scale in lora_layer .scaling .values ()
79
- ]
74
+ self .scaling = torch .nn .ParameterList (
75
+ [
76
+ torch .nn .Parameter (torch .as_tensor (scale ), requires_grad = False ).to (
77
+ self .base_layer .weight .device
78
+ )
79
+ for scale in lora_layer .scaling .values ()
80
+ ]
81
+ )
80
82
self .lora_dropout = nn .ModuleList ({})
81
83
self .adapter_name_to_index = {}
82
84
self .index_to_adapter_name = {}
Original file line number Diff line number Diff line change @@ -380,10 +380,23 @@ def forward_pass(model, forward_pass_callback=None):
380
380
]
381
381
assert sorted (tensor_name ) == sorted (tensors )
382
382
383
+ @pytest .mark .cuda
384
+ def test_changing_lora_device (self ):
385
+ model = one_adapter_model ().cuda ()
386
+
387
+ replace_lora_layers_with_quantizable_layers (model )
388
+ dummy_inputs = torch .randn (10 , 10 ).cuda ()
389
+
390
+ _ = model (dummy_inputs )
391
+
392
+ model .cpu ()
393
+
394
+ _ = model (dummy_inputs .cpu ())
395
+
383
396
384
397
def _is_frozen (quantizer ):
385
398
return (
386
- quantizer ._allow_overwrite == False
387
- and quantizer .min .requires_grad == False
388
- and quantizer .max .requires_grad == False
399
+ not quantizer ._allow_overwrite
400
+ and not quantizer .min .requires_grad
401
+ and not quantizer .max .requires_grad
389
402
)
You can’t perform that action at this time.
0 commit comments