Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,9 @@ def instance_norm(self, inputs, input_types):
data = inputs[0]
data_type = input_types[0]
channels = self.infer_shape(data)
running_mean = inputs[3]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a most recent api change from pytorch or a long ignored params on our side? The former will need us to think about BC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter I think. The "track_running_stats" has been ignored in the unit test.
By the way, there will be another PR later about BC, also on a similar issue.

running_var = inputs[4]
use_input_stats = inputs[5]

if isinstance(inputs[1], _expr.Expr) and isinstance(inputs[2], _expr.Expr):
scale = center = True
Expand All @@ -1401,6 +1404,20 @@ def instance_norm(self, inputs, input_types):
beta = _create_typed_const(np.zeros([int(channels[1])]), data_type)

epsilon = float(inputs[7])

if not use_input_stats:
return _op.nn.batch_norm(
data,
gamma,
beta,
running_mean,
running_var,
axis=1,
epsilon=epsilon,
center=center,
scale=scale,
)[0]

return _op.nn.instance_norm(
data, gamma, beta, axis=1, epsilon=epsilon, center=center, scale=scale
)
Expand Down
2 changes: 2 additions & 0 deletions tests/python/frontend/pytorch/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,8 @@ def test_forward_instancenorm():
for ins_norm, inp in [
(torch.nn.InstanceNorm2d(16), inp_2d),
(torch.nn.InstanceNorm3d(16), inp_3d),
(torch.nn.InstanceNorm2d(16, track_running_stats=True), inp_2d),
(torch.nn.InstanceNorm3d(16, track_running_stats=True), inp_3d),
]:
verify_model(ins_norm.eval(), input_data=inp)

Expand Down