MCPcopy
hub / github.com/huggingface/pytorch-image-models / test_model_forward_torchscript

Function test_model_forward_torchscript

tests/test_models.py:431–446  ·  view source on GitHub ↗

Run a single forward pass with each model

(model_name, batch_size)

Source from the content-addressed store, hash-verified

429 'model_name', list_models(exclude_filters=EXCLUDE_FILTERS + EXCLUDE_JIT_FILTERS, name_matches_cfg=True))
430@pytest.mark.parametrize('batch_size', [1])
431def test_model_forward_torchscript(model_name, batch_size):
432 """Run a single forward pass with each model"""
433 input_size = _get_input_size(model_name=model_name, target=TARGET_JIT_SIZE)
434 if max(input_size) > MAX_JIT_SIZE:
435 pytest.skip("Fixed input size model > limit.")
436
437 with set_scriptable(True):
438 model = create_model(model_name, pretrained=False)
439 model.eval()
440
441 model = torch.jit.script(model)
442 model.to(torch_device)
443 outputs = model(torch.randn((batch_size, *input_size)))
444
445 assert outputs.shape[0] == batch_size
446 assert not torch.isnan(outputs).any(), 'Output included NaNs'
447
448
449EXCLUDE_FEAT_FILTERS = [

Callers

nothing calls this directly

Calls 4

set_scriptableClass · 0.90
create_modelFunction · 0.90
_get_input_sizeFunction · 0.85
toMethod · 0.80

Tested by

no test coverage detected