Skip to content
Closed
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
15 changes: 9 additions & 6 deletions test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,18 @@ def test_classification_model(model_fn, dev):
real_image = kwargs.pop("real_image", False)

model = model_fn(**kwargs)
model.eval().to(device=dev)
x = _get_image(input_shape=input_shape, real_image=real_image, device=dev)
out = model(x)
# We use float64 (.double()) to reduce differences between cpu and gpu result
model.eval().to(device=dev).double()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
model.eval().to(device=dev).double()
model.eval().to(device=dev, dtype=torch.double)

x = _get_image(input_shape=input_shape, real_image=real_image, device=dev).double()
with torch.no_grad(), freeze_rng_state():
out = model(x)
_assert_expected(out.cpu(), model_name, prec=1e-3)
assert out.shape[-1] == num_classes
_check_jit_scriptable(model, (x,), unwrapper=script_model_unwrapper.get(model_name, None), eager_out=out)
_check_fx_compatible(model, x, eager_out=out)

if dev == "cuda":
with torch.cuda.amp.autocast():
with torch.cuda.amp.autocast(), torch.no_grad(), freeze_rng_state():
out = model(x)
# See autocast_flaky_numerics comment at top of file.
if model_name not in autocast_flaky_numerics:
Expand Down Expand Up @@ -782,8 +784,9 @@ def test_detection_model(model_fn, dev):
real_image = kwargs.pop("real_image", False)

model = model_fn(**kwargs)
model.eval().to(device=dev)
x = _get_image(input_shape=input_shape, real_image=real_image, device=dev)
# We use float64 (.double()) to reduce differences between cpu and gpu result
model.eval().to(device=dev).double()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
model.eval().to(device=dev).double()
model.eval().to(device=dev, dtype=torch.double)

x = _get_image(input_shape=input_shape, real_image=real_image, device=dev).double()
Copy link
Contributor

Choose a reason for hiding this comment

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

Extend _get_image to also get a dtype arg.

model_input = [x]
with torch.no_grad(), freeze_rng_state():
out = model(model_input)
Expand Down