check_sparse_tensor_invariants#
- static check_sparse_tensor_invariants(enable=True)[source]#
A tool to control checking sparse tensor invariants.
The following options exists to manage sparsr tensor invariants checking in sparse tensor construction
Using a context manager
with torch.sparse.check_sparse_tensor_invariants(): run_my_model()
Using a procedural approach
prev_checks_enabled = torch.sparse.check_sparse_tensor_invariants.is_enabled() torch.sparse.check_sparse_tensor_invariants.enable() run_my_model() if not prev_checks_enabled: torch.sparse.check_sparse_tensor_invariants.disable()
Using function decoration
@torch.sparse.check_sparse_tensor_invariants() def run_my_model(): ... run_my_model()
Using
check_invariants
keyword argument in sparse tensor constructor call. For example>>> torch.sparse_csr_tensor([0, 1, 3], [0, 1], [1, 2], check_invariants=True) Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: `crow_indices[..., -1] == nnz` is not satisfied.
- static disable()[source]#
Disable sparse tensor invariants checking in sparse tensor constructors.
See
torch.sparse.check_sparse_tensor_invariants.enable()
for more information.
- static enable()[source]#
Enable sparse tensor invariants checking in sparse tensor constructors.
注意
By default, the sparse tensor invariants checks are disabled. Use
torch.sparse.check_sparse_tensor_invariants.is_enabled()
to retrieve the current state of sparse tensor invariants checking.注意
The sparse tensor invariants check flag is effective to all sparse tensor constructors, both in Python and ATen.
The flag can be locally overridden by the
check_invariants
optional argument of the sparse tensor constructor functions.
- static is_enabled()[source]#
Return True if the sparse tensor invariants checking is enabled.
注意
Use
torch.sparse.check_sparse_tensor_invariants.enable()
ortorch.sparse.check_sparse_tensor_invariants.disable()
to manage the state of the sparse tensor invariants checks.