PyTorch torch._assert Function
PyTorch torch reference manual
torch._assert is a function in PyTorch used for assertion checks. If the condition is False, a RuntimeError is raised.
Function definition
torch._assert(condition, message)
Usage examples
Example
import
torch
Example Code
condition
=
True
torch._assert
(
condition
,
"Assertion failed!"
)
(
"Assertion passed!"
)
Failing example
try
:
torch._assert
(
False
,
"This will fail"
)
except
RuntimeError
as
e:
(
f
"Caught error: {e}"
)