if isinstance(value, PIL.Image.Image):
                value = np.asarray(value)
        if config.DECORD_AVAILABLE and "decord" in sys.modules:
            # We need to import torch first, otherwise later it can cause issues
            # e.g. "RuntimeError: random_device could not be read"
            # when running `torch.tensor(value).share_memory_()`
            if config.TORCH_AVAILABLE:
                import torch  # noqa
            from decord import VideoReader

            if isinstance(value, VideoReader):
                value._hf_bridge_out = lambda x: jnp.array(np.asarray(x))
                return value

        # using global variable since `jaxlib.xla_extension.Device` is not serializable neither
        # with `pickle` nor with `dill`, so we need to use a global variable instead
        global DEVICE_MAPPING
        if DEVICE_MAPPING is None:
            DEVICE_MAPPING = self._map_devices_to_str()