MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / gather_nd

Function gather_nd

examples/pytorch/decoding/utils/decoding.py:141–152  ·  view source on GitHub ↗
(params, indices)

Source from the content-addressed store, hash-verified

139
140
141def gather_nd(params, indices):
142 indices = indices.t().long()
143 ndim = indices.size(0)
144 idx = torch.zeros_like(indices[0]).long()
145 m = 1
146
147 for i in range(ndim)[::-1]:
148 idx += indices[i] * m
149 m *= params.size(i)
150
151 params = params.reshape((-1, *tuple(torch.tensor(params.size()[ndim:]))))
152 return params[idx]
153
154
155def gather_tree(step_ids, parent_ids, max_sequence_lengths, end_token):

Callers 1

forwardMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected