MCPcopy Create free account
hub / github.com/OpenSparseLLMs/MoM / tensorize

Method tensorize

training/flame/data.py:186–197  ·  view source on GitHub ↗
(example: Dict[str, Any])

Source from the content-addressed store, hash-verified

184 examples = [{'input_ids': example} for example in examples]
185
186 def tensorize(example: Dict[str, Any]) -> Dict[str, Any]:
187 tensorized = {}
188 for key in ['input_ids', 'offsets']:
189 if key not in example:
190 continue
191 if isinstance(example[key], List):
192 tensorized[key] = torch.tensor(example[key], dtype=torch.long)
193 elif isinstance(example[key], np.ndarray):
194 tensorized[key] = torch.from_numpy(example[key])
195 else:
196 tensorized[key] = example[key]
197 return tensorized
198
199 examples = list(map(tensorize, examples))
200

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected