Skip to content
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

keep parameter names from PyTorch #5887

Merged
merged 1 commit into from
Jun 22, 2020
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
4 changes: 2 additions & 2 deletions python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2354,8 +2354,8 @@ def convert_params(graph, state_dict):
elif full_attr in state_dict:
torch_tensor = state_dict[full_attr]
tensor, var = _get_tensor_and_var(torch_tensor,
full_attr_node_name)
param_tensors[full_attr_node_name] = tensor
full_attr)
param_tensors[full_attr] = tensor
params[full_attr_node_name] = var

return params, param_tensors, packed_param_map
Expand Down
9 changes: 9 additions & 0 deletions tests/python/frontend/pytorch/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,12 @@ def fn(t1, t2):
verify_model(fn, input_data=[tensor1, tensor2])


def test_weight_names():
tm = torch.jit.trace(torch.nn.Linear(3, 4), [torch.randn(2, 3)])
mod, params = relay.frontend.from_pytorch(tm, [('input', (2, 3))])
assert set(params.keys()) == set(n for n, p in tm.named_parameters())


def test_forward_matmul():
torch.set_grad_enabled(False)

Expand Down Expand Up @@ -2546,8 +2552,11 @@ def test_forward_pretrained_bert_base_uncased():


if __name__ == "__main__":
# some structural tests
test_forward_traced_function()
test_forward_dtypes()
test_weight_names()

# Single operator tests
test_forward_add()
test_forward_subtract()
Expand Down