Skip to content

Commit

Permalink
Update aten.hardtanh support
Browse files Browse the repository at this point in the history
Add converter for hardtanh similar to that of clamp
  • Loading branch information
TedThemistokleous committed Oct 24, 2023
1 parent c405f46 commit e237c6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions py/torch_migraphx/fx/converters/aten_ops_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,19 @@ def aten_ops_split(mgx_module, node, args, kwargs):
return slice_nodes


@migraphx_converter(torch.ops.aten.hardtanh.default)
@migraphx_converter(torch.ops.aten.clamp.default)
def aten_ops_clamp(mgx_module, node, args, kwargs):
assert len(args) >= 1
min_, max_ = None, None
if node.target == torch.ops.aten.hardtanh.default:
min_, max_ = -1, 1

acc_kwargs = {
"input": args[0],
"min": args[1] if len(args) >= 2 else None,
"max": args[2] if len(args) == 3 else None
"min": args[1] if len(args) >= 2 else min_,
"max": args[2] if len(args) == 3 else max_
}

return acc_ops_converters.acc_ops_clamp(mgx_module, node, (), acc_kwargs)


Expand Down
3 changes: 2 additions & 1 deletion tests/dynamo/converters/test_activations_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
pytest.skip(allow_module_level=True)


@pytest.mark.parametrize('op_alias', [torch.ops.aten.clamp.default])
@pytest.mark.parametrize('op_alias', [torch.ops.aten.clamp.default,
torch.ops.aten.hardtanh.default])
@pytest.mark.parametrize('inp_size', [(4, 2, 7), (128, 2048),
(1, 3, 6, 128, 128)])
def test_clamp(op_alias, inp_size):
Expand Down

0 comments on commit e237c6e

Please sign in to comment.