MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTSD / rpadding

Function rpadding

generation_utils.py:329–345  ·  view source on GitHub ↗
(input_ids, channels, tokenizer)

Source from the content-addressed store, hash-verified

327
328
329def rpadding(input_ids, channels, tokenizer):
330 attention_masks = [np.ones(inputs.shape[0]) for inputs in input_ids]
331 max_length = max(ids.shape[0] for ids in input_ids)
332 padded_input_ids, padded_attns = [], []
333
334 for ids, attn in zip(input_ids, attention_masks):
335 pad_len = max_length - ids.shape[0]
336 input_pad = np.full((pad_len, channels), 1024)
337 input_pad[:, 0] = tokenizer.pad_token_id
338 padded_input_ids.append(np.concatenate([input_pad, ids]))
339 attn_pad = np.zeros(pad_len)
340 padded_attns.append(np.concatenate([attn_pad, attn]))
341
342 input_ids = torch.tensor(np.stack(padded_input_ids))
343 attention_mask = torch.tensor(np.stack(padded_attns))
344
345 return input_ids, attention_mask
346
347
348def find_max_valid_positions(C: torch.Tensor, invalid_value=1024) -> torch.Tensor:

Callers 2

streamerFunction · 0.90
process_batchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected