Skip to content

Instantly share code, notes, and snippets.

@wanchaol
Created April 26, 2019 18:16
Show Gist options
  • Save wanchaol/bb44846d4fcbf6447152a79a6b666c0c to your computer and use it in GitHub Desktop.
Save wanchaol/bb44846d4fcbf6447152a79a6b666c0c to your computer and use it in GitHub Desktop.
@torch.jit.script
def test_if_refinement(weight, bias):
# type: (Optional[Tensor], Optional[Tensor]) -> Tuple[Optional[int], Optional[int]]
if weight is not None and bias is not None:
grad_weight = 1
grad_bias = 2
elif weight is not None:
grad_weight = 2
grad_bias = None
elif bias is not None:
grad_weight = None
grad_bias = 5
else:
grad_weight = None
grad_bias = None
return (grad_weight, grad_bias)
======
RuntimeError:
Return value was annotated as having type Tuple[Optional[int], Optional[int]] but is actually of type Tuple[Optional[int], Optional[Optional[int]]]:
grad_weight = 2
grad_bias = None
elif bias is not None:
grad_weight = None
grad_bias = 5
else:
grad_weight = None
grad_bias = None
return (grad_weight, grad_bias)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment