Convert PaddlePaddle tensors in multimodal inputs to NumPy arrays. Args: tasks: List of tasks containing multimodal inputs.
(tasks: List[Any])
| 1201 | |
| 1202 | |
| 1203 | def to_numpy(tasks: List[Any]): |
| 1204 | """ |
| 1205 | Convert PaddlePaddle tensors in multimodal inputs to NumPy arrays. |
| 1206 | |
| 1207 | Args: |
| 1208 | tasks: List of tasks containing multimodal inputs. |
| 1209 | """ |
| 1210 | try: |
| 1211 | for task in tasks: |
| 1212 | if not hasattr(task, "multimodal_inputs"): |
| 1213 | continue |
| 1214 | images = task.multimodal_inputs.get("images", None) |
| 1215 | if isinstance(images, paddle.Tensor): |
| 1216 | llm_logger.debug(f"Convert image to numpy, shape: {images.shape}") |
| 1217 | task.multimodal_inputs["images"] = images.numpy() |
| 1218 | |
| 1219 | list_keys = [ |
| 1220 | "image_features", |
| 1221 | "video_features", |
| 1222 | "audio_features", |
| 1223 | ] |
| 1224 | for key in list_keys: |
| 1225 | value = task.multimodal_inputs.get(key, None) |
| 1226 | if value is None: |
| 1227 | continue |
| 1228 | if isinstance(value, list): |
| 1229 | task.multimodal_inputs[key] = [v.numpy() for v in value] |
| 1230 | except Exception as e: |
| 1231 | llm_logger.warning(f"Failed to convert to numpy: {e}") |
| 1232 | |
| 1233 | |
| 1234 | def to_tensor(tasks: List[Any]): |