Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support hardswish function #100

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 1 addition & 18 deletions thunder/tests/opinfos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,32 +1608,15 @@ def hardswish_error_generator(op, device, dtype=torch.float32, **kwargs):
sample_input_generator=elementwise_unary_generator,
error_input_generator=hardswish_error_generator,
torch_reference=_elementwise_unary_torch(torch.nn.functional.hardswish),
dtypes=(datatypes.floating,),
test_directives=(
# PyTorch does not support bool for both CPU and CUDA hardswish
DecorateInfo(
pytest.mark.xfail,
"test_core_vs_torch_consistency",
dtypes=(datatypes.bool8,),
),
# PyTorch does not support complex types for both the CPU and CUDA hardswish
DecorateInfo(
pytest.mark.xfail,
"test_core_vs_torch_consistency",
dtypes=(datatypes.complexfloating,),
),
# PyTorch does not support CPU Half hardswish
DecorateInfo(
pytest.mark.xfail,
"test_core_vs_torch_consistency",
dtypes=(datatypes.float16,),
devicetypes=(devices.DeviceType.CPU,),
),
# PyTorch does not support integer types for both the CPU and CUDA hardswish
DecorateInfo(
pytest.mark.xfail,
"test_core_vs_torch_consistency",
dtypes=(datatypes.int16, datatypes.int32, datatypes.int64, datatypes.int8, datatypes.uint8),
),
# TODO: we might have a tolerance issue here with hardsiwsh, a function of relu6
DecorateInfo(
pytest.mark.xfail(strict=False),
Expand Down
3 changes: 3 additions & 0 deletions thunder/torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,9 @@ def relu6(a: TensorProxy, /, inplace: bool = False) -> TensorLike:
@torchsymbol(torch.nn.functional.hardswish, id="torch.hardswish", is_method=False)
def hardswish(a: TensorProxy, /, inplace: bool = False) -> TensorLike:
t-vi marked this conversation as resolved.
Show resolved Hide resolved
utils.check(not inplace, lambda: f"hardswish only supports inplace=False", exception_type=NotImplementedError)
utils.check(a.dtype in (torch.float16, torch.float32, torch.float64),
t-vi marked this conversation as resolved.
Show resolved Hide resolved
lambda: f"hardswish only supports floating point dtypes, got {a.dtype}",
exception_type=TypeError)
return a * relu6(a + 3) / 6


Expand Down