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

Function torch_assert_close

tests/unit/util.py:137–148  ·  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

135
136
137def torch_assert_close(actual, expected, **kwargs) -> None:
138 """
139 Compare two tensors or non-tensor numbers for their closeness.
140
141 Add msg=blah to add an additional comment to when assert fails.
142
143 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
144 For example for bf16 it is `rtol=1.6e-2` and `atol=1e-5`.
145
146 The check doesn&#x27;t assert when `|a - b| <= (atol + rtol * |b|)`
147 """
148 torch.testing.assert_close(actual, expected, **kwargs)
149
150
151def torch_assert_dicts_of_tensors_equal(actual, expected, **kwargs):

Callers 7

testMethod · 0.90
testMethod · 0.90
test_ulysses_sp_hfMethod · 0.90
test_tiled_mlpMethod · 0.90
allclose_on_all_ranksFunction · 0.85

Calls

no outgoing calls

Tested by 6

testMethod · 0.72
testMethod · 0.72
test_ulysses_sp_hfMethod · 0.72
test_tiled_mlpMethod · 0.72