(self, chunk: Any, start_pos: int)
| 10932 | index += self._encode_media_batch(uncached, index) |
| 10933 | |
| 10934 | def _positions_for_chunk(self, chunk: Any, start_pos: int) -> np.ndarray: |
| 10935 | n_tokens = int(mtmd_cpp.mtmd_input_chunk_get_n_tokens(chunk)) |
| 10936 | if not mtmd_cpp.mtmd_decode_use_mrope(self.ctx): |
| 10937 | return np.arange(start_pos, start_pos + n_tokens, dtype=np.int32) |
| 10938 | chunk_type = int(mtmd_cpp.mtmd_input_chunk_get_type(chunk)) |
| 10939 | if chunk_type == mtmd_cpp.MTMD_INPUT_CHUNK_TYPE_AUDIO: |
| 10940 | positions = np.empty((4, n_tokens), dtype=np.int32) |
| 10941 | positions[:] = np.arange(start_pos, start_pos + n_tokens, dtype=np.int32) |
| 10942 | return positions.reshape(-1) |
| 10943 | image_tokens = mtmd_cpp.mtmd_input_chunk_get_tokens_image(chunk) |
| 10944 | if image_tokens is None: |
| 10945 | raise CompletionRequestValidationError("MTMD image chunk has no image tokens") |
| 10946 | positions = np.empty((4, n_tokens), dtype=np.int32) |
| 10947 | for index in range(n_tokens): |
| 10948 | pos = mtmd_cpp.mtmd_image_tokens_get_decoder_pos( |
| 10949 | image_tokens, |
| 10950 | llama_cpp.llama_pos(start_pos), |
| 10951 | index, |
| 10952 | ) |
| 10953 | positions[0, index] = int(pos.t) |
| 10954 | positions[1, index] = int(pos.y) |
| 10955 | positions[2, index] = int(pos.x) |
| 10956 | positions[3, index] = int(pos.z) |
| 10957 | return positions.reshape(-1) |
| 10958 | |
| 10959 | def build_prompt_plan( |
| 10960 | self, |
no test coverage detected