A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.pytorch.org/docs/stable/generated/torch.sparse.check_sparse_tensor_invariants.html below:

check_sparse_tensor_invariants — PyTorch 2.7 documentation

check_sparse_tensor_invariants
class torch.sparse.check_sparse_tensor_invariants(enable=True)[source][source]

A tool to control checking sparse tensor invariants.

The following options exists to manage sparsr tensor invariants checking in sparse tensor construction:

  1. Using a context manager:

    with torch.sparse.check_sparse_tensor_invariants():
        run_my_model()
    
  2. 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()
    
  3. Using function decoration:

    @torch.sparse.check_sparse_tensor_invariants()
    def run_my_model():
        ...
    
    run_my_model()
    
  4. 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][source]

Disable sparse tensor invariants checking in sparse tensor constructors.

See torch.sparse.check_sparse_tensor_invariants.enable() for more information.

static enable()[source][source]

Enable sparse tensor invariants checking in sparse tensor constructors.

Note

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][source]

Return True if the sparse tensor invariants checking is enabled.

Docs

Access comprehensive developer documentation for PyTorch

View Docs Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials Resources

Find development resources and get your questions answered

View Resources

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4