Skip to content

Commit 3a2bf05

Browse files
committed
tmp
1 parent 2d847f7 commit 3a2bf05

7 files changed

Lines changed: 42 additions & 17 deletions

File tree

‎apps/llm/app/llm/index.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function LLMScreen() {
4545
const textInputRef = useRef<TextInput>(null);
4646
const { setGlobalGenerating } = useContext(GeneratingContext);
4747

48+
let llm = Object();
4849

4950
const tokenCount = llm.isReady ? llm.getGeneratedTokenCount() : 0;
5051
const { stats, onMessageSend } = useLLMStats(

‎apps/llm/app/multimodal_llm/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function MultimodalLLMScreen() {
6464
const [error, setError] = useState<string | null>(null);
6565

6666
const vlm = useLLM({
67-
model: models.llm.lfm2_5_vl_450m(),
67+
model: models.llm.gemma4_e2b(),
6868
});
6969
const tokenCount = vlm.isReady ? vlm.getGeneratedTokenCount() : 0;
7070
const { stats, onMessageSend } = useLLMStats(

‎packages/react-native-executorch/common/runner/encoders/audio_encoder.cpp‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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");

‎packages/react-native-executorch/common/runner/encoders/audio_encoder.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AudioEncoder : public IEncoder {
3434
::executorch::extension::Module *module_;
3535
int32_t last_token_count_ = 0;
3636
std::vector<float> padded_wav_;
37-
std::vector<uint8_t> padded_mask_;
37+
int64_t num_blocks_scalar_ = 0;
3838
};
3939

4040
} // namespace executorch::extension::llm

‎packages/react-native-executorch/common/runner/sampler.cpp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,33 @@ int32_t Sampler::sample_topp(T *probabilities, float coin) {
9292
n0++;
9393
}
9494
}
95+
96+
std::sort(probindex.get(), probindex.get() + n0,
97+
[](const ProbIndex<T> &a, const ProbIndex<T> &b) {
98+
return a.prob > b.prob;
99+
});
100+
101+
// truncate the list where cumulative probability exceeds topp
102+
T cumulative_prob = 0;
103+
int last_idx = n0 - 1;
104+
for (int i = 0; i < n0; i++) {
105+
cumulative_prob += probindex[i].prob;
106+
if (static_cast<float>(cumulative_prob) > topp_) {
107+
last_idx = i;
108+
break;
109+
}
110+
}
111+
112+
// sample from the truncated list
113+
float r = coin * static_cast<float>(cumulative_prob);
114+
T cdf = 0;
115+
for (int i = 0; i <= last_idx; i++) {
116+
cdf += probindex[i].prob;
117+
if (r < static_cast<float>(cdf)) {
118+
return probindex[i].index;
119+
}
120+
}
121+
return probindex[last_idx].index;
95122
}
96123

97124
// Mask logits outside the top-k by rank to -inf. Ties at the k-th boundary

‎packages/react-native-executorch/src/constants/modelRegistry.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ export const models = {
488488
// pick a model by capability ("LLM") rather than by modality.
489489
lfm2_5_vl_1_6b: base(M.LFM2_5_VL_1_6B_QUANTIZED),
490490
lfm2_5_vl_450m: base(M.LFM2_5_VL_450M_QUANTIZED),
491+
gemma4_e2b: base(M.GEMMA4_E2B_QUANTIZED)
491492
},
492493
classification: {
493494
efficientnet_v2_s: variant(EFFICIENTNET_V2_S_VARIANTS),

‎packages/react-native-executorch/src/constants/modelUrls.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const GEMMA4_E2B_QUANTIZED = {
134134
modelName: 'gemma4-e2b-quantized',
135135
modelSource:
136136
// 'http://localhost:9001/ptes/iter206_xnnpack_audio_rsqrt_baked_mask_relshift_idx_prefill2048.pte',
137-
'http://localhost:9001/experiments/outputs/exp107f_mm_s4048_noqkvo_wav.pte',
137+
'http://localhost:9001/experiments/outputs/exp115_mm_s4048_levers.pte',
138138
tokenizerSource: 'http://localhost:9001/gemma4_e2b/tokenizer.json',
139139
tokenizerConfigSource:
140140
'http://localhost:9001/gemma4_e2b/gemma4_tokenizer_config.json',

0 commit comments

Comments
 (0)