MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT-LLM / column_linear_forward

Function column_linear_forward

tests/unittest/_torch/multi_gpu/test_linear.py:112–147  ·  view source on GitHub ↗
(x, hidden_size, dtype, tensor_parallel_size,
                          tensor_parallel_rank, weights)

Source from the content-addressed store, hash-verified

110
111@torch.inference_mode
112def column_linear_forward(x, hidden_size, dtype, tensor_parallel_size,
113 tensor_parallel_rank, weights):
114
115 x = x.cuda()
116 l0 = Linear(
117 in_features=hidden_size,
118 out_features=hidden_size,
119 bias=False,
120 dtype=dtype,
121 mapping=Mapping(
122 world_size=tensor_parallel_size,
123 tp_size=tensor_parallel_size,
124 rank=tensor_parallel_rank,
125 ),
126 tensor_parallel_mode=TensorParallelMode.COLUMN,
127 gather_output=True,
128 )
129 l0.load_weights([dict(weight=weights[0])])
130 l0.cuda()
131
132 l0 = torch.compile(l0, fullgraph=True)
133 output = l0.forward(x)
134
135 # torch run
136 l0 = nn.Linear(in_features=hidden_size,
137 out_features=hidden_size,
138 bias=False,
139 dtype=dtype)
140 l0.weight.data.copy_(weights[0])
141 l0.cuda()
142
143 torch_output = l0.forward(x)
144
145 # compare
146 torch.cuda.synchronize()
147 torch.testing.assert_close(output, torch_output)
148
149
150@torch.inference_mode

Callers

nothing calls this directly

Calls 6

load_weightsMethod · 0.95
forwardMethod · 0.95
LinearClass · 0.90
MappingClass · 0.90
synchronizeMethod · 0.80
compileMethod · 0.45

Tested by

no test coverage detected