Skip to content

Fix edge cases on test_backbone_utils when the sampled node is buffer with integer value #6091

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

Merged
Merged
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
16 changes: 8 additions & 8 deletions test/test_backbone_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ def test_forward_backward(self, model_name):
out_agg = 0
for node_out in out.values():
if isinstance(node_out, Sequence):
out_agg += sum(o.mean() for o in node_out if o is not None)
out_agg += sum(o.float().mean() for o in node_out if o is not None)
elif isinstance(node_out, Mapping):
out_agg += sum(o.mean() for o in node_out.values() if o is not None)
out_agg += sum(o.float().mean() for o in node_out.values() if o is not None)
else:
# Assume that the only other alternative at this point is a Tensor
out_agg += node_out.mean()
out_agg += node_out.float().mean()
out_agg.backward()

def test_feature_extraction_methods_equivalence(self):
Expand Down Expand Up @@ -224,12 +224,12 @@ def test_jit_forward_backward(self, model_name):
out_agg = 0
for node_out in fgn_out.values():
if isinstance(node_out, Sequence):
out_agg += sum(o.mean() for o in node_out if o is not None)
out_agg += sum(o.float().mean() for o in node_out if o is not None)
elif isinstance(node_out, Mapping):
out_agg += sum(o.mean() for o in node_out.values() if o is not None)
out_agg += sum(o.float().mean() for o in node_out.values() if o is not None)
else:
# Assume that the only other alternative at this point is a Tensor
out_agg += node_out.mean()
out_agg += node_out.float().mean()
out_agg.backward()

def test_train_eval(self):
Expand All @@ -239,7 +239,7 @@ def __init__(self):
self.dropout = torch.nn.Dropout(p=1.0)

def forward(self, x):
x = x.mean()
x = x.float().mean()
x = self.dropout(x) # dropout
if self.training:
x += 100 # add
Expand Down Expand Up @@ -330,4 +330,4 @@ def forward(self, x):
# Check forward
out = model(self.inp)
# And backward
out["leaf_module"].mean().backward()
out["leaf_module"].float().mean().backward()