MCPcopy Create free account
hub / github.com/apache/tvm / DTensor

Function DTensor

python/tvm/relax/script/parser/dist.py:69–103  ·  view source on GitHub ↗
(
    shape: list[PrimExpr | str] | None = None,
    dtype: str | None = None,
    device_mesh: DeviceMesh | str = DeviceMesh([], Range(0, 1)),
    placement: Placement | str = "",
    *,
    ndim: int = -1,
)

Source from the content-addressed store, hash-verified

67
68
69def DTensor(
70 shape: list[PrimExpr | str] | None = None,
71 dtype: str | None = None,
72 device_mesh: DeviceMesh | str = DeviceMesh([], Range(0, 1)),
73 placement: Placement | str = "",
74 *,
75 ndim: int = -1,
76) -> DTensorProxy:
77 # scalar tensor case
78 if shape is not None and len(shape) == 0:
79 shape = []
80 if isinstance(shape, str) and dtype is None:
81 dtype = shape
82 shape = None
83
84 if shape is not None and not isinstance(shape, tuple | list):
85 raise ValueError(f"shape must be a list or tuple, but got: {shape}")
86 if isinstance(device_mesh, str):
87 if not IRBuilder.is_in_scope():
88 return (
89 DTensorProxy(
90 TensorProxy(shape, dtype, None, ndim), DeviceMesh([], Range(0, 1)), ""
91 ),
92 )
93 name, index = device_mesh.split("[")
94 index = int(index[:-1])
95 frames = IRBuilder.current().frames
96 for f in frames:
97 if isinstance(f, IRModuleFrame):
98 device_mesh = f.global_infos[name][index]
99 break
100 assert isinstance(device_mesh, DeviceMesh)
101 if isinstance(placement, str):
102 placement = Placement.from_text(placement)
103 return DTensorProxy(TensorProxy(shape, dtype, None, ndim), device_mesh, placement)
104
105
106__all__ = ["DTensor", "device_mesh"]

Callers

nothing calls this directly

Calls 8

DeviceMeshClass · 0.90
RangeClass · 0.90
DTensorProxyClass · 0.85
TensorProxyClass · 0.85
is_in_scopeMethod · 0.80
from_textMethod · 0.80
splitMethod · 0.45
currentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…