(self, frame_rows: list[list[int]])
| 280 | self.state_feeds[str(spec["cached_positions_input_name"])] = positions |
| 281 | |
| 282 | def run_frames(self, frame_rows: list[list[int]]) -> tuple[np.ndarray, int] | None: |
| 283 | if not frame_rows: |
| 284 | return None |
| 285 | num_quantizers = int(self.codec_meta["codec_config"]["num_quantizers"]) |
| 286 | frame_count = len(frame_rows) |
| 287 | audio_codes = np.zeros((1, frame_count, num_quantizers), dtype=np.int32) |
| 288 | for frame_index, frame_row in enumerate(frame_rows): |
| 289 | for channel_index in range(num_quantizers): |
| 290 | audio_codes[0, frame_index, channel_index] = int(frame_row[channel_index] if channel_index < len(frame_row) else 0) |
| 291 | feeds: dict[str, np.ndarray] = { |
| 292 | "audio_codes": audio_codes, |
| 293 | "audio_code_lengths": np.asarray([frame_count], dtype=np.int32), |
| 294 | } |
| 295 | feeds.update(self.state_feeds) |
| 296 | outputs = self.session.run(None, feeds) |
| 297 | output_names = [output.name for output in self.session.get_outputs()] |
| 298 | named_outputs = dict(zip(output_names, outputs, strict=True)) |
| 299 | for spec in self.transformer_specs: |
| 300 | self.state_feeds[str(spec["input_name"])] = named_outputs[str(spec["output_name"])] |
| 301 | for spec in self.attention_specs: |
| 302 | self.state_feeds[str(spec["offset_input_name"])] = named_outputs[str(spec["offset_output_name"])] |
| 303 | self.state_feeds[str(spec["cached_keys_input_name"])] = named_outputs[str(spec["cached_keys_output_name"])] |
| 304 | self.state_feeds[str(spec["cached_values_input_name"])] = named_outputs[str(spec["cached_values_output_name"])] |
| 305 | self.state_feeds[str(spec["cached_positions_input_name"])] = named_outputs[str(spec["cached_positions_output_name"])] |
| 306 | return ( |
| 307 | named_outputs["audio"], |
| 308 | int(named_outputs["audio_lengths"].reshape(-1)[0]), |
| 309 | ) |
| 310 | |
| 311 | |
| 312 | class OrtCpuRuntime: |
no outgoing calls
no test coverage detected