The obvious issue is that both of these call get_device_from_ctx which references the unimported Device(). Importing it would cause a circular dependency. This does not appear to be the root of the issue, as per the logic of the Stream class, and the cuda model, self._device_id can never be None. In short, we can get rid of util.device_from_ctx