modelscope icon indicating copy to clipboard operation
modelscope copied to clipboard

Batch and single are not uniform

Open ezeli opened this issue 1 year ago • 1 comments

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.

ezeli avatar Mar 20 '23 06:03 ezeli

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]

ezeli avatar Mar 20 '23 07:03 ezeli

thanks, can you open a pull request to fix this issue?

wenmengzhou avatar Mar 29 '23 03:03 wenmengzhou

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.

github-actions[bot] avatar Apr 29 '23 01:04 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar May 05 '23 01:05 github-actions[bot]