def METHOD_NAME(
    i: int,
    module: Module,
    input: Any,
    kwargs: Dict[str, Any],
    device: Optional[Union[int, torch.device]] = None,
    stream: Optional[torch.cuda.Stream] = None,
) -> None:
    torch.set_grad_enabled(grad_enabled)
    if device is None:
        t = get_a_var(input)
        if t is None:
            with lock:
                results[i] = ExceptionWrapper(
                    where=f"in replica {i}, no device was provided and no tensor input was found; "
                    "device cannot be resolved")
            return
        device = t.get_device()
    if stream is None:
        stream = torch.cuda.current_stream(device)
    try:
        with torch.cuda.device(device), torch.cuda.stream(stream), autocast(enabled=autocast_enabled):
            # this also avoids accidental slicing of `input` if it is a Tensor
            if not isinstance(input, (list, tuple)):
                input = (input,)
            output = module(*input, **kwargs)
        with lock:
            results[i] = output
    except Exception:
        with lock:
            results[i] = ExceptionWrapper(
                where=f"in replica {i} on device {device}")