@@ -88,30 +88,26 @@ Result<EValue> AudioEncoder::encode(const MultimodalInput &input) {
8888 static_cast <double >(kAudioBlockKMax ) / 16000.0 );
8989 const int64_t n_padded = k_blocks * kSamplesPerBlock ;
9090
91- // Own the padded waveform and the attention_mask buffers for the lifetime
92- // of this call; from_blob below borrows without copying. Mask is bool
93- // (1 byte per element): true at the first n_valid samples (real PCM),
94- // false at the zero-padded tail. Matches the iter191+ export at
95- // iter201_mm_4method_dynaudio_prefill2048_export.py:484-486 — `forward(
96- // self, waveform[1,N] fp32, attention_mask[1,N] bool)` .
91+ // Own the padded waveform for the lifetime of this call; from_blob below
92+ // borrows without copying. The current export takes
93+ // forward(waveform[1, 7680*k] fp32, num_blocks: int64 scalar)
94+ // — input 1 is a rank-0 Long telling the encoder how many of the K_MAX
95+ // blocks contain real PCM. Passing a 2-d mask here trips "Attempted to
96+ // change tensor rank: old=0, new=2" .
9797 padded_wav_.assign (static_cast <size_t >(n_padded), 0 .0f );
9898 std::memcpy (padded_wav_.data (), wav.samples .data (),
9999 static_cast <size_t >(n_valid) * sizeof (float ));
100100
101- padded_mask_.assign (static_cast <size_t >(n_padded), uint8_t {0 });
102- if (n_valid > 0 ) {
103- std::memset (padded_mask_.data (), 1 , static_cast <size_t >(n_valid));
104- }
101+ num_blocks_scalar_ = k_blocks;
105102
106103 auto wav_tensor = ::executorch::extension::from_blob (
107104 padded_wav_.data (), {1 , static_cast <SizesType>(n_padded)},
108105 ::executorch::aten::ScalarType::Float);
109106
110- auto mask_tensor = ::executorch::extension::from_blob (
111- padded_mask_.data (), {1 , static_cast <SizesType>(n_padded)},
112- ::executorch::aten::ScalarType::Bool);
107+ auto num_blocks_tensor = ::executorch::extension::from_blob (
108+ &num_blocks_scalar_, {}, ::executorch::aten::ScalarType::Long);
113109
114- std::vector<EValue> args = {EValue (*wav_tensor), EValue (*mask_tensor )};
110+ std::vector<EValue> args = {EValue (*wav_tensor), EValue (*num_blocks_tensor )};
115111 auto exec_result = ET_UNWRAP (module_->execute (kAudioEncoderMethod , args));
116112 ET_CHECK_OR_RETURN_ERROR (!exec_result.empty (), InvalidState,
117113 " audio_encoder returned no outputs" );
0 commit comments