Skip to content

Commit 7f88321

Browse files
committed
enable 8bit and fsdp tests for xpu
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
1 parent ca5c4a9 commit 7f88321

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

tests/test_linear8bitlt.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ def test_linear_serialization(
172172
assert torch.allclose(x_first.grad, x_third.grad, atol=1e-5)
173173

174174

175-
@pytest.fixture
176-
def linear8bit(requires_cuda):
175+
@pytest.fixture(params=get_available_devices(no_cpu=True))
176+
def linear8bit(request):
177+
device = request.param
177178
linear = torch.nn.Linear(32, 96)
178179
linear_custom = Linear8bitLt(
179180
linear.in_features,
@@ -188,7 +189,7 @@ def linear8bit(requires_cuda):
188189
has_fp16_weights=False,
189190
)
190191
linear_custom.bias = linear.bias
191-
linear_custom = linear_custom.cuda()
192+
linear_custom = linear_custom.to(device)
192193
return linear_custom
193194

194195

tests/test_modules.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,34 +448,36 @@ def test_4bit_embedding_warnings(device, caplog):
448448
assert any("inference" in msg for msg in caplog.messages)
449449

450450

451-
def test_4bit_embedding_weight_fsdp_fix(requires_cuda):
451+
@pytest.mark.parametrize("device", get_available_devices(no_cpu=True))
452+
def test_4bit_embedding_weight_fsdp_fix(device):
452453
num_embeddings = 64
453454
embedding_dim = 32
454455

455456
module = bnb.nn.Embedding4bit(num_embeddings=num_embeddings, embedding_dim=embedding_dim)
456457

457-
module.cuda()
458+
module.to(device)
458459

459460
module.weight.quant_state = None
460461

461-
input_tokens = torch.randint(low=0, high=num_embeddings, size=(1,), device="cuda")
462+
input_tokens = torch.randint(low=0, high=num_embeddings, size=(1,), device=device)
462463

463464
module(input_tokens)
464465

465466
assert module.weight.quant_state is not None
466467

467468

468-
def test_4bit_linear_weight_fsdp_fix(requires_cuda):
469+
@pytest.mark.parametrize("device", get_available_devices(no_cpu=True))
470+
def test_4bit_linear_weight_fsdp_fix(device):
469471
inp_size = 64
470472
out_size = 32
471473

472474
module = bnb.nn.Linear4bit(inp_size, out_size)
473475

474-
module.cuda()
476+
module.to(device)
475477

476478
module.weight.quant_state = None
477479

478-
input_tensor = torch.randn((1, inp_size), device="cuda")
480+
input_tensor = torch.randn((1, inp_size), device=device)
479481

480482
module(input_tensor)
481483

0 commit comments

Comments
 (0)