class_docstr: A tensor with mutable shape information.
  Inspired by `Ideal FLOPS counter <https://dev-discuss.pytorch.org/t/the-ideal-pytorch-flop-counter-with-torch-dispatch/505>`__.
class_docstr_tok: ["A","tensor","with","mutable","shape","information",".","Inspired","by","`","Ideal","FLOPS","counter","<","https",":","\/\/dev-discuss.pytorch.org\/t\/the-ideal-pytorch-flop-counter-with-torch-dispatch\/505",">","`","__","."]
code: def __new__(cls, elem: torch.Tensor, shape: bool | tuple = False):
      assert isinstance(elem, torch.Tensor) and not isinstance(
          elem, ShapeTensor
      )
      # The wrapping tensor (ShapeTensor) shouldn't hold any memory for the class in question,
      # but it should still advertise the same device as before.
      r: ShapeTensor = torch.Tensor._make_wrapper_subclass(  # type: ignore
          cls,
          elem.size(),
          strides=elem.stride(),
          storage_offset=elem.storage_offset(),
          # TODO: clone storage aliasing
          dtype=elem.dtype,
          layout=elem.layout,
          device=elem.device,
          requires_grad=elem.requires_grad,
      )
      # ...the real tensor is held as an element on the tensor.
      r.elem = elem
      if shape is True:
          r.real_shape = MutableShape(*elem.size())
      elif shape is False:
          r.real_shape = None
      else:
          r.real_shape = MutableShape(shape)
      return r
  
imports: from __future__ import annotations
  import functools
  import logging
  import traceback
  from typing import Union, Tuple, Callable, Iterable, Any, NamedTuple, Dict, cast, overload
  import torch
  from torch import nn
  from torch.utils.hooks import RemovableHandle
  from nni.mutable import MutableExpression, Mutable, LabeledMutable, Sample, SampleValidationError
  from nni.mutable.mutable import _mutable_equal
  from .misc import is_leaf_module, argument_in_spec
label_desc: Use image node_id 1 for calling the ShapeTensor obj's underlying member method code with example usage: obj.__new__(cls, elem, shape) and returns: r