Generic function to stack frames for audio processing Abstracts out the StackAudioFrames logic used by ultravox
| 713 | // Generic function to stack frames for audio processing |
| 714 | // Abstracts out the StackAudioFrames logic used by ultravox |
| 715 | ggml_tensor * clip_graph::build_stack(ggml_tensor * cur, int32_t stack_factor, int32_t n_embed) { |
| 716 | if (stack_factor <= 1) { |
| 717 | return cur; |
| 718 | } |
| 719 | |
| 720 | int64_t total_elements = ggml_nelements(cur); |
| 721 | int64_t stride = n_embed * stack_factor; |
| 722 | |
| 723 | // Calculate padded length |
| 724 | int64_t padded_len = GGML_PAD(total_elements, stride); |
| 725 | int64_t pad = padded_len - total_elements; |
| 726 | |
| 727 | if (pad > 0) { |
| 728 | // Pad the tensor to make it divisible by stride |
| 729 | cur = ggml_view_1d(ctx0, cur, total_elements, 0); |
| 730 | cur = ggml_pad(ctx0, cur, pad, 0, 0, 0); |
| 731 | } |
| 732 | |
| 733 | // Reshape to [stride, padded_len / stride] |
| 734 | cur = ggml_view_2d(ctx0, cur, stride, padded_len / stride, |
| 735 | ggml_row_size(cur->type, stride), 0); |
| 736 | return cur; |
| 737 | } |
| 738 | |
| 739 | // aka pixel_shuffle / pixel_unshuffle / patch_merger (Kimi-VL) |
| 740 | // support dynamic resolution |
nothing calls this directly
no test coverage detected