Skip to content

Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.

added post and pretraining docs

Karen Mosoyan4ca75ed56f7f
diff --git a/docs/posttraining.md b/docs/posttraining.md
new file mode 100644
index 0000000..b5fdbef
--- /dev/null
+++ b/docs/posttraining.md
@@ -0,0 +1,128 @@
+## Transcription Training
+```mermaid
+graph LR
+ %% Inputs
+ AT_pair[Audio-Text pair] --> A_in[Audio]
+ AT_pair --> T_in[Text]
+ A_in --> A_emb[Audio Embedding]
+ T_in --> T_emb[Text Embedding]
+
+ %% Embeddings to Encoder
+ A_emb --> Enc[Shared Encoder]
+ T_emb --> Enc
+
+ %% Encoder to Latents
+ Enc --> ZA[z-audio]
+ Enc --> ZT[z-text]
+
+ %% Audio Transcription Branch
+ ZA --> Tr_dec[Transcription Head]
+ Tr_dec --> A_loss[Audio Transcription Loss]
+
+ %% Contrastive Alignment Branch
+ ZA --> Proj[Audio Projector]
+ Proj --> C_loss[SigLip Loss]
+ ZT --> C_loss
+```
+
+## Audio-Text Tool call training V1
+```mermaid
+graph LR
+ %% Inputs
+ AT_pair[Audio-Text prompt pair] --> A_in[Audio Prompt]
+ AT_pair --> T_in[Text Prompt]
+ A_in --> A_emb[Audio Embedding]
+ T_in --> T_emb[Text Embedding]
+ P_in[Tool List] --> T_emb
+
+ %% Embeddings to Encoder
+ T_emb --> Enc[Shared Encoder]
+ A_emb --> Enc
+
+ %% Encoder to Latents
+ Enc --> ZA[z-audio]
+ Enc --> ZP[z-list]
+ Enc --> ZT[z-text]
+
+ %% Contrastive Alignment Branch
+ ZA --> Proj[Audio Projector]
+ Proj --> C_loss[SigLip Loss]
+ ZT --> C_loss
+
+ %% Merged Latents
+ ZA --> ZAP[z-audio-list]
+ ZP --> ZTP
+ ZP --> ZAP
+ ZT --> ZTP[z-text-list]
+
+ %% Tool Call Branch
+ ZAP --> Tool_dec[Tool Call Head]
+ ZTP --> Tool_dec
+ Tool_dec --> Tool_loss[Text Tool Call Loss]
+ Tool_dec --> ATool_loss[Audio Tool Call Loss]
+```
+
+## Audio-Text Tool call training V2
+```mermaid
+graph LR
+ %% Inputs
+ AT_pair[Audio-Text prompt pair] --> A_in[Audio Prompt]
+ AT_pair --> T_in[Text Prompt]
+ A_in --> A_emb[Audio Embedding]
+ T_in --> T_emb[Text Embedding]
+
+ %% Embeddings to Encoder
+ T_emb --> Enc[Shared Encoder]
+ A_emb --> Enc
+
+ %% Encoder to Latents
+ Enc --> ZA[z-audio]
+ Enc --> ZT[z-text]
+
+ %% Contrastive Alignment Branch
+ ZA --> Proj[Audio Projector]
+ Proj --> C_loss[SigLip Loss]
+ ZT --> C_loss
+
+ %% Tool Call Branch
+ ZA --> Tool_dec[Tool Call Head]
+ ZT --> Tool_dec
+ P_in[Tool List] --> Tool_dec
+ Tool_dec --> Tool_loss[Text Tool Call Loss]
+ Tool_dec --> ATool_loss[Audio Tool Call Loss]
+```
+
+## Audio-Text Tool call training V3
+```mermaid
+graph LR
+ %% Inputs
+ AT_pair[Audio-Text prompt pair] --> A_in[Audio Prompt]
+ AT_pair --> T_in[Text Prompt]
+ A_in --> A_emb[Audio Embedding]
+ T_in --> T_emb[Text Embedding]
+ A_emb --> A_emb_f[Audio + '$' + Tool List Embedding]
+ T_emb --> T_emb_f[Text + '$' + Tool List Embedding]
+ Tool_emb[Tool List Embedding] --> A_emb_f
+ Tool_emb --> T_emb_f
+
+ %% Embeddings to Encoder
+ T_emb_f --> Enc[Shared Encoder]
+ A_emb_f --> Enc
+
+ %% Encoder to Latents
+ Enc --> ZA[z-audio]
+ Enc --> ZT[z-text]
+
+ %% Contrastive Alignment Branch
+ ZA --> Proj[Audio Projector]
+ Proj --> C_loss[SigLip Loss]
+ ZT --> C_loss
+
+ %% Tool Call Branch
+ ZA --> Tool_dec[Tool Call Head]
+ ZT --> Tool_dec
+ Tool_dec --> Tool_loss[Text Tool Call Loss]
+ Tool_dec --> ATool_loss[Audio Tool Call Loss]
+```
+
+Audio transcription training and tool call training can be done at the same time, while the Audio tool call training should be done separately at the end.
\ No newline at end of file
diff --git a/docs/pretraining.md b/docs/pretraining.md
new file mode 100644
index 0000000..6432d3b
--- /dev/null
+++ b/docs/pretraining.md
@@ -0,0 +1,64 @@
+### Stage 1 (Unlabeled): Recon + Adversarial Alignment
+
+```mermaid
+graph LR
+ %% Inputs
+ A_in[Audio] --> A_emb[Audio Embedding]
+ T_in[Text] --> T_emb[Text Embedding]
+
+ %% Embeddings to Encoder
+ A_emb --> Enc[Shared Encoder]
+ T_emb --> Enc
+
+ %% Encoder to Latents
+ Enc --> ZA[z-audio]
+ Enc --> ZT[z-text]
+
+ %% Audio Reconstruction Branch
+ ZA --> A_dec[Audio Decoder]
+ A_dec --> A_loss[Audio Reconstruction Loss]
+
+ %% Text Reconstruction Branch
+ ZT --> T_dec[Text Decoder]
+ T_dec --> T_loss[Text Reconstruction Loss]
+
+ %% Adversarial Alignment Branch
+ ZA --> Proj[Audio Projector]
+ Proj --> Adv[Alignment Loss]
+ ZT --> Adv
+```
+
+Let $a \sim \mathcal{D}_a$ denote an audio sample and $x \sim \mathcal{D}_x$ denote a text sample (unpaired across datasets). A shared encoder $f_\theta(\cdot)$ maps either modality to a latent representation:
+$$z_a = f_\theta(a), \qquad z_x = f_\theta(x).$$
+
+We attach modality-specific reconstruction decoders:
+$$\hat a = r_{\phi_a}(z_a), \qquad \hat x = r_{\phi_x}(z_x),$$
+with reconstruction losses (chosen to match the underlying representation, e.g. $\ell_1/\ell_2$ for continuous targets or cross-entropy for discrete tokens):
+$$\mathcal{L}_{\mathrm{rec\text{-}a}}(a) = \ell_a(\hat a, a), \qquad \mathcal{L}_{\mathrm{rec\text{-}x}}(x) = \ell_x(\hat x, x).$$
+
+Taking expectations over the unlabeled datasets yields:
+$$\mathcal{L}_{\mathrm{rec\text{-}a}} = \mathbb{E}_{a\sim \mathcal{D}_a}\!\left[\mathcal{L}_{\mathrm{rec\text{-}a}}(a)\right], \qquad \mathcal{L}_{\mathrm{rec\text{-}x}} = \mathbb{E}_{x\sim \mathcal{D}_x}\!\left[\mathcal{L}_{\mathrm{rec\text{-}x}}(x)\right].$$
+
+To align the audio and text latent distributions while allowing audio-specific detail to be stripped, we introduce an audio projector $p_\psi(\cdot)$:
+$$u_a = p_\psi(z_a).$$
+
+We train a modality discriminator $d_\omega(\cdot)\in(0,1)$ to predict whether its input came from the audio pathway (label $1$ for $u_a$) or the text pathway (label $0$ for $z_x$). The discriminator is trained with binary cross-entropy:
+$$\mathcal{L}_D(\omega) = \mathbb{E}_{a\sim \mathcal{D}_a}\!\left[-\log d_\omega(u_a)\right] + \mathbb{E}_{x\sim \mathcal{D}_x}\!\left[-\log\big(1-d_\omega(z_x)\big)\right].$$
+
+Stage 1 training follows the standard minimax objective: reconstruction decoders (and the shared encoder) minimize reconstruction error, while the encoder/projector are trained adversarially to *fool* the discriminator. Let $\Theta=\{\theta,\phi_a,\phi_x,\psi\}$ denote parameters of the shared encoder, reconstruction decoders, and projector. We optimize:
+$$\min_{\Theta}\;\max_{\omega}\;\; \mathcal{L}_{\mathrm{rec\text{-}a}} + \mathcal{L}_{\mathrm{rec\text{-}x}} \;-\;\lambda_{\mathrm{adv}}\,\mathcal{L}_D(\omega;\Theta),$$
+where $\lambda_{\mathrm{adv}}\ge 0$ controls the strength of adversarial alignment.
+
+## **Spec and Ablations**
+1. **Audio Embedding**: There are essentially two options. First, we can take the raw waverform and and use convolutions on it Moonshine style to construct features. Second, we can generate the MEL bins and process them Whisper style. We can either do patches ViT style or again just conv over MEL Whisper style. The audio dataset we will be using is TBD (maybe granary), the audio will be prepared by augmenting it with slight natural noise, then we mask out different portions of the MEL bin and then the final prediction must be done to recreate the inital unmasked mel bins.
+
+2. **Audio Decoder**: The audio decoder that we will be using has to reconstruct the MEL bins. We will probably make everything fixed size, padded to 30s. The decoder is going to be a shallow non-causal transformer with learned positional embeddings as the initial query. The decoder has to be lightweight so that the encoder generates informative latents and handles most of the processing
+
+3. **Text Embedding and Decoder**: This will be very standard, we will have a UL2 setup with a tokenizer and embedding layer, and then a standard transformer decoder. The text dataset we will be using is TBD (maybe FineWebEdu). We will have a minor adjustment to UL2, instead of predicting just the noised parts we will reconstruct the whole sequence, to match what the audio decoder is doing better.
+
+4. **Adversarial Alignment**: The discriminator will be something like a 2 layer MLP mixer taking in the matrix valued latent and outputting a number. We should either do a MLP mixer or a pool and then MLP to properly handle the matrixness of the latent. We might have to do a hyperparameter sweep directed towards getting the best update parameters for the discriminator.
+
+5. **Encoder**: The encoder will be a memory mixer like what we have implemented already.
+
+6. **Audio Projector**: The audio projector will be a simple linear multiplication on the latent multiplying across the hidden dimension.
+