Skip to content

Commit 8f15aca

Browse files
Merge branch 'main' into dev/gokul/atan2-support
2 parents 8271025 + a374b48 commit 8f15aca

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

coreai_torch/_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from ._composite_declaration import generate_composite_decl
4747
from ._type_mapping import (
4848
TORCH_TO_COREAI_DTYPE,
49-
_get_coreai_to_numpy_dtype,
5049
_get_coreai_to_torch_dtype,
5150
)
5251

@@ -1056,13 +1055,14 @@ def replace_pad_with_mode(
10561055
padding[2 * dim] = inverted_padding[i]
10571056
padding[2 * dim + 1] = inverted_padding[i + 1]
10581057

1059-
# padding_value is ignored for non-constant modes, but the op requires it to
1060-
# be a constant of the input dtype (a cast op is rejected by the backend).
1061-
np_dtype = _get_coreai_to_numpy_dtype()[x.type.element_type]
1058+
# padding_value is ignored for non-constant modes, but the op still requires
1059+
# a constant operand of the input's exact dtype (a cast op is rejected by the
1060+
# backend). Passing the MLIR element type keeps the constant's dtype exact
1061+
# (e.g. bf16) instead of round-tripping through a lossy numpy dtype map.
10621062
return coreai.pad(
10631063
x,
10641064
np.array(padding, dtype=np.uint32),
1065-
coreai.constant(np.array(0.0, dtype=np_dtype)),
1065+
coreai.constant(0.0, dtype=x.type.element_type),
10661066
padding_mode=padding_mode,
10671067
)
10681068

tests/ops/test_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7448,7 +7448,7 @@ def forward(self, x: Tensor) -> Tensor:
74487448
]
74497449

74507450

7451-
@pytest.mark.parametrize("dtype", [torch.float32, torch.float16])
7451+
@pytest.mark.parametrize("dtype", [torch.float32, torch.float16, torch.bfloat16])
74527452
@pytest.mark.parametrize("mode", ["reflect", "replicate"])
74537453
@pytest.mark.parametrize("pad, input_shape", _PAD_SHARED_CASES)
74547454
async def test_reflect_replicate_pad(

0 commit comments

Comments
 (0)