def scatter(input, devices, streams=None):
if streams is None:<EOL><INDENT>streams = [None] * len(devices)<EOL><DEDENT>if isinstance(input, list):<EOL><INDENT>chunk_size = (len(input) - <NUM_LIT:1>) // len(devices) + <NUM_LIT:1><EOL>outputs = [<EOL>scatter(input[i], [devices[i // chunk_size]],<EOL>[streams[i // chunk_size]]) for i in range(len(input))<EOL>]<EOL>return outputs<EOL><DEDENT>elif isinstance(input, torch.Tensor):<EOL><INDENT>output = input.contiguous()<EOL>stream = streams[<NUM_LIT:0>] if output.numel() > <NUM_LIT:0> else None<EOL>with torch.cuda.device(devices[<NUM_LIT:0>]), torch.cuda.stream(stream):<EOL><INDENT>output = output.cuda(devices[<NUM_LIT:0>], non_blocking=True)<EOL><DEDENT>return output<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>'.format(type(input)))<EOL><DEDENT>
Scatters tensor across multiple GPUs.