MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / torch_assert_close

Function torch_assert_close

tests/unit/util.py:135–146  ·  view source on GitHub ↗

Compare two tensors or non-tensor numbers for their closeness. Add msg=blah to add an additional comment to when assert fails. For default values of `rtol` and `atol` which are dtype dependent, see the table at https://docs.pytorch.org/docs/stable/testing.html#torch.testing.assert_clo

(actual, expected, **kwargs)

Source from the content-addressed store, hash-verified

133
134
135def torch_assert_close(actual, expected, **kwargs) -> None:
136 """
137 Compare two tensors or non-tensor numbers for their closeness.
138
139 Add msg=blah to add an additional comment to when assert fails.
140
141 For default values of `rtol` and `atol` which are dtype dependent, see the table at https://docs.pytorch.org/docs/stable/testing.html#torch.testing.assert_close
142 For example for bf16 it is `rtol=1.6e-2` and `atol=1e-5`.
143
144 The check doesn&#x27;t assert when `|a - b| <= (atol + rtol * |b|)`
145 """
146 torch.testing.assert_close(actual, expected, **kwargs)
147
148
149def torch_assert_dicts_of_tensors_equal(actual, expected, **kwargs):

Calls 1

assert_closeMethod · 0.80