Repository navigation
feat: add LFM 3 (1.7B, VL 2B, Audio 2B) - #1582
Open
msluszniak wants to merge 3 commits into
Open
msluszniak wants to merge 3 commits into
msluszniak wants to merge 3 commits into
Conversation
msluszniak
marked this pull request as draft
October 28, 2026 12:10
msluszniak
marked this pull request as ready for review
October 28, 2026 13:40
msluszniak
commented
Oct 28, 2026
barhanc
reviewed
Oct 28, 2026
Comment on lines
+349
to
+353
| const stats = prefillEmbeddings(embedding, numAudioTokens, prefillLen); | ||
| const numTokens = totStats.numTokens + stats.numTokens; | ||
| const durationMs = totStats.durationMs + stats.durationMs; | ||
| const tokensPerSecond = durationMs > 0 ? (numTokens / durationMs) * 1000 : 0; | ||
| totStats = { numTokens, durationMs, tokensPerSecond }; |
Member
There was a problem hiding this comment.
You can use the combineStats helper here as in gemma example.
Comment on lines
+335
to
+340
| const chunkSamples = Math.min(numSamples - offset, chunkStride); | ||
| // Right-pad to window + k * hop samples, as the feature extractor does. | ||
| const padded = | ||
| chunkSamples <= window ? window : window + Math.ceil((chunkSamples - window) / hop) * hop; | ||
| const numFrames = 1 + (padded - window) / hop; | ||
| const numAudioTokens = Math.ceil(numFrames / framesPerToken); |
Member
There was a problem hiding this comment.
Suggested change
| const chunkSamples = Math.min(numSamples - offset, chunkStride); | |
| // Right-pad to window + k * hop samples, as the feature extractor does. | |
| const padded = | |
| chunkSamples <= window ? window : window + Math.ceil((chunkSamples - window) / hop) * hop; | |
| const numFrames = 1 + (padded - window) / hop; | |
| const numAudioTokens = Math.ceil(numFrames / framesPerToken); | |
| const chunkSamples = Math.min(numSamples - offset, chunkStride); | |
| // Right-pad to window + k * hop samples, as the feature extractor does. | |
| const k = Math.ceil((chunkSamples - window) / hop); | |
| const padded = chunkSamples <= window ? window : window + k * hop; | |
| const numFrames = 1 + (padded - window) / hop; | |
| const numAudioTokens = Math.ceil(numFrames / framesPerToken); |
Comment on lines
+88
to
95
| const modality: Modality = variant === 'vision' ? 'image' : 'audio'; | ||
|
|
||
| if (!modalities?.includes(modality)) { | ||
| throw RnExecuTorchError( | ||
| 'INVALID_ARGUMENT', | ||
| `Multimodal vision-language model requires 'image' in modalities.` | ||
| `Multimodal model with an ${modality} encoder requires '${modality}' in modalities.` | ||
| ); | ||
| } |
Member
There was a problem hiding this comment.
Maybe something like
const specModalities = {
vision: ['image'],
audio: ['audio'],
omni: ['image', 'audio'],
}[variant];
if (
modalities?.length !== specModalities.length ||
modalities.some((m) => !specModalities.includes(m))
) {
throw RnExecuTorchError(
'INVALID_ARGUMENT',
`Multimodal model requires [${specModalities}] modalities.`
);
}
// ...
let imgShape: readonly [1, 3, number, number];
let numVisualTokens: number;
if (modalities.includes('image')) {
imgShape = [1, 3, ...dims.constant('imgH', 'imgW')];
numVisualTokens = dim('visualTokens', 'constant');
}
let audioSamples: Range;
let framesPerToken: number;
if (modalities.includes('audio')) {
[audioSamples] = dims.range('audioSamples');
[framesPerToken] = model.execute('get_audio_frames_per_token', [], []) as [number];
}with checks changed to
if (!modalities.includes('image')) {
throw RnExecuTorchError('INVALID_ARGUMENT', 'prefill: This model has no vision encoder.');
}would allow better extensibility also for omni model.
Member
|
I tested the new models in example app and they work great. I'm super impressed by the audio model---the prefill and decode speed and accuracy of the transcription are incredible (especially compared to Gemma) 🤯. I don't have iOS device to test the MLX versions so that will have to wait for tomorrow. |
Member
Author
|
@kfaracik could you check the MLX and XNNPACK variants of these models on iOS since you have told me you have been adding these models. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
audio_encodermodel (LLM_AUDIO_SPEC) in place ofvision_encoder.</think>with thinking off.Introduces a breaking change?
Type of change
Tested on
Testing instructions
Screenshots
Related issues
Checklist
Additional notes