Skip to content

Commit 7253bec

Browse files
cyyeverydshieh
authored andcommitted
Fix tensor dtype mismatch (huggingface#36985)
* Fix tensor dtype mismatch * update * update --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
1 parent ef73811 commit 7253bec

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/models/mixtral/test_modeling_mixtral.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def test_small_model_logits(self):
486486
# Note: Key 9 is currently set for MI300, but may need potential future adjustments for H100s,
487487
# considering differences in hardware processing and potential deviations in output.
488488
EXPECTED_LOGITS = {
489-
7: torch.Tensor([[0.1670, 0.1620, 0.6094], [-0.8906, -0.1588, -0.6060], [0.1572, 0.1290, 0.7246]]).to(
489+
7: torch.Tensor([[0.1640, 0.1621, 0.6093], [-0.8906, -0.1640, -0.6093], [0.1562, 0.1250, 0.7226]]).to(
490490
torch_device
491491
),
492492
8: torch.Tensor([[0.1631, 0.1621, 0.6094], [-0.8906, -0.1621, -0.6094], [0.1572, 0.1270, 0.7227]]).to(
@@ -499,6 +499,8 @@ def test_small_model_logits(self):
499499
with torch.no_grad():
500500
logits = model(dummy_input).logits
501501

502+
logits = logits.float()
503+
502504
torch.testing.assert_close(
503505
logits[0, :3, :3], EXPECTED_LOGITS[self.cuda_compute_capability_major_version], atol=1e-3, rtol=1e-3
504506
)
@@ -525,7 +527,7 @@ def test_small_model_logits_batched(self):
525527
# considering differences in hardware processing and potential deviations in generated text.
526528
EXPECTED_LOGITS_LEFT = {
527529
7: torch.Tensor(
528-
[[0.1750, 0.0537, 0.7007], [0.1750, 0.0537, 0.7007], [0.1750, 0.0537, 0.7007]],
530+
[[0.1904, 0.0500, 0.7187], [0.1933, 0.0515, 0.7187], [0.2001, 0.0559, 0.7148]],
529531
).to(torch_device),
530532
8: torch.Tensor([[0.1914, 0.0508, 0.7188], [0.1953, 0.0510, 0.7227], [0.1973, 0.0562, 0.7148]]).to(
531533
torch_device
@@ -537,7 +539,7 @@ def test_small_model_logits_batched(self):
537539

538540
EXPECTED_LOGITS_LEFT_UNPADDED = {
539541
7: torch.Tensor(
540-
[[0.2212, 0.5200, -0.3816], [0.8213, -0.2313, 0.6069], [0.2664, -0.7090, 0.2468]],
542+
[[0.2236, 0.5195, -0.3828], [0.8203, -0.2275, 0.6054], [0.2656, -0.7070, 0.2460]],
541543
).to(torch_device),
542544
8: torch.Tensor([[0.2217, 0.5195, -0.3828], [0.8203, -0.2295, 0.6055], [0.2676, -0.7109, 0.2461]]).to(
543545
torch_device
@@ -548,7 +550,7 @@ def test_small_model_logits_batched(self):
548550
}
549551

550552
EXPECTED_LOGITS_RIGHT_UNPADDED = {
551-
7: torch.Tensor([[0.2205, 0.1232, -0.1611], [-0.3484, 0.3030, -1.0312], [0.0742, 0.7930, 0.7969]]).to(
553+
7: torch.Tensor([[0.2167, 0.1269, -0.1640], [-0.3496, 0.2988, -1.0312], [0.0688, 0.7929, 0.8007]]).to(
552554
torch_device
553555
),
554556
8: torch.Tensor([[0.2178, 0.1260, -0.1621], [-0.3496, 0.2988, -1.0312], [0.0693, 0.7930, 0.8008]]).to(
@@ -561,6 +563,7 @@ def test_small_model_logits_batched(self):
561563

562564
with torch.no_grad():
563565
logits = model(dummy_input, attention_mask=attention_mask).logits
566+
logits = logits.float()
564567

565568
torch.testing.assert_close(
566569
logits[0, :3, :3], EXPECTED_LOGITS_LEFT[self.cuda_compute_capability_major_version], atol=1e-3, rtol=1e-3

0 commit comments

Comments
 (0)