Convert NumPy arrays in multimodal inputs to Paddle tensors. Args: tasks (tuple): ([request], bsz)
(tasks: List[Any])
| 1232 | |
| 1233 | |
| 1234 | def to_tensor(tasks: List[Any]): |
| 1235 | """ |
| 1236 | Convert NumPy arrays in multimodal inputs to Paddle tensors. |
| 1237 | |
| 1238 | Args: |
| 1239 | tasks (tuple): ([request], bsz) |
| 1240 | """ |
| 1241 | try: |
| 1242 | for task in tasks: |
| 1243 | multimodal_inputs = getattr(task, "multimodal_inputs", None) |
| 1244 | if not multimodal_inputs: |
| 1245 | continue |
| 1246 | # tensor keys |
| 1247 | tensor_keys = [ |
| 1248 | "images", |
| 1249 | "patch_idx", |
| 1250 | "token_type_ids", |
| 1251 | "position_ids", |
| 1252 | "attention_mask_offset", |
| 1253 | ] |
| 1254 | |
| 1255 | list_keys = [ |
| 1256 | "image_features", |
| 1257 | "video_features", |
| 1258 | "audio_features", |
| 1259 | ] |
| 1260 | |
| 1261 | llm_logger.debug(f"Converting multimodal inputs to tensor...{tensor_keys + list_keys}") |
| 1262 | |
| 1263 | for key in tensor_keys: |
| 1264 | value = multimodal_inputs.get(key) |
| 1265 | if value is None: |
| 1266 | continue |
| 1267 | if not isinstance(value, paddle.Tensor): |
| 1268 | multimodal_inputs[key] = paddle.to_tensor(value) |
| 1269 | |
| 1270 | for key in list_keys: |
| 1271 | value = multimodal_inputs.get(key) |
| 1272 | if value is None: |
| 1273 | continue |
| 1274 | if isinstance(value, list): |
| 1275 | multimodal_inputs[key] = [paddle.to_tensor(v) for v in value] |
| 1276 | except Exception as e: |
| 1277 | llm_logger.warning(f"Tensor conversion failed: {type(e).__name__}: {e}") |
| 1278 | |
| 1279 | |
| 1280 | def do_nothing(*args, **kwargs): |