MCPcopy Create free account
hub / github.com/huggingface/transformers / _assert_tensors_equal

Function _assert_tensors_equal

tests/test_modeling_bart.py:534–546  ·  view source on GitHub ↗

If tensors not close, or a and b arent both tensors, raise a nice Assertion error.

(a, b, atol=1e-12, prefix="")

Source from the content-addressed store, hash-verified

532
533
534def _assert_tensors_equal(a, b, atol=1e-12, prefix=""):
535 """If tensors not close, or a and b arent both tensors, raise a nice Assertion error."""
536 if a is None and b is None:
537 return True
538 try:
539 if torch.allclose(a, b, atol=atol):
540 return True
541 raise
542 except Exception:
543 msg = "{} != {}".format(a, b)
544 if prefix:
545 msg = prefix + ": " + msg
546 raise AssertionError(msg)
547
548
549def _long_tensor(tok_lst):

Callers 4

test_advanced_inputsMethod · 0.85
test_enro_forwardMethod · 0.85
test_tokenizationMethod · 0.85
test_mnli_inferenceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected