(
shape: list[PrimExpr | str] | None = None,
dtype: str | None = None,
device_mesh: DeviceMesh | str = DeviceMesh([], Range(0, 1)),
placement: Placement | str = "",
*,
ndim: int = -1,
)
| 67 | |
| 68 | |
| 69 | def 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"] |
nothing calls this directly
no test coverage detected
searching dependent graphs…