modelscope
modelscope copied to clipboard
Batch and single are not uniform
https://github.com/modelscope/modelscope/blob/fe673953b1f8cfe2a2f1ed2ef7c3207fefc28f43/modelscope/pipelines/base.py#L298
should be changed to:
out[k] = element[batch_idx:batch_idx+1]
In this way, _process_batch is unified with _process_single when calling the postprocess function.
And when processing other types of elements, it should be iterated. For example, when output_hidden_states=True, the tuple object will be returned. For example:
out = {}
for k, element in batched_out.items():
if element is not None:
if isinstance(element, torch.Tensor):
out[k] = element[batch_idx:batch_idx+1]
elif isinstance(element, (tuple, list)) and isinstance(element[0], torch.Tensor):
out[k] = type(element)(e[batch_idx:batch_idx+1] for e in element)
else:
out[k] = element[batch_idx:batch_idx+1]
thanks, can you open a pull request to fix this issue?
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.