If tensors not close, or a and b arent both tensors, raise a nice Assertion error.
(a, b, atol=1e-12, prefix="")
| 532 | |
| 533 | |
| 534 | def _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 | |
| 549 | def _long_tensor(tok_lst): |
no outgoing calls
no test coverage detected