Skip to content

A research project focused on developing a lightweight neural voice cloning and speech synthesis system, optimized for deployment on edge devices.

Python

Update from @is/reinforcement-learning

IgorSwat8a8c0b7795f8
diff --git a/echo/configs/model/rl_round5.json b/echo/configs/model/rl_round5.json
new file mode 100644
index 0000000..a19e296
--- /dev/null
+++ b/echo/configs/model/rl_round5.json
@@ -0,0 +1,17 @@
+{
+ "meta": {
+ "version": 1,
+ "name": "rl-round5-winner"
+ },
+ "init_from": "runs/rl/round_5",
+ "prefix_blocking": {
+ "enabled": true
+ },
+ "cfg": {
+ "mode": "student",
+ "guidance_scale": 2.0
+ },
+ "architecture": {
+ "intermediate_size": 2048
+ }
+}
diff --git a/echo/configs/rl/base.json b/echo/configs/rl/base.json
index 7474de6..a18c27e 100644
--- a/echo/configs/rl/base.json
+++ b/echo/configs/rl/base.json
@@ -32,7 +32,7 @@
"enabled": true,
"tracking_uri": "https://mlflow.swmansion.com",
"experiment_id": "3",
- "username": null,
- "password": null
+ "username": "igor",
+ "password": "passwordpassword"
}
}
diff --git a/echo/configs/rl/mine.json b/echo/configs/rl/mine.json
index 1efb4fe..2d728e0 100644
--- a/echo/configs/rl/mine.json
+++ b/echo/configs/rl/mine.json
@@ -32,7 +32,7 @@
"enabled": true,
"tracking_uri": "https://mlflow.swmansion.com",
"experiment_id": "3",
- "username": null,
- "password": null
+ "username": "igor",
+ "password": "passwordpassword"
}
}
diff --git a/echo/configs/training/qat_w4a16.json b/echo/configs/training/qat_w4a16.json
index 176c3be..bdba2ba 100644
--- a/echo/configs/training/qat_w4a16.json
+++ b/echo/configs/training/qat_w4a16.json
@@ -1,14 +1,14 @@
{
"meta": {
"version": 1,
- "name": "echo-v0.0.2-p4-qat-w4a16",
+ "name": "echo-rl-round5-qat-w4a16",
"seed": 4321,
- "notes": "W4A16 quantization-aware training of the final p3 model (runs/v0.0.2/p3/final): symmetric int4 weights, one scale per group of 32 inputs, in the decoder linears, learning the distribution of its frozen full-precision self. Forward KL only, 1 epoch, LR 1e-5 with a cosine decay to 2e-6. Run with --bits 4 --group-size 32 --no-activations."
+ "notes": "W4A16 quantization-aware training of the RL round-5 winner (runs/rl/round_5), learning the distribution of its frozen full-precision self on the traced main-path states of s8, s8 + rmc025 and s6 + rmc025 (masking.samplers) plus the polish state. Forward KL only. Symmetric int4 weights, one scale per group of 32 inputs, in the decoder linears. 5 epochs, LR 1e-5 with a cosine decay to 1e-6. PTQ KL 0.580 dev / 0.501 test (s8, 20 batches); the 2026-11-07 probes (1 GPU, 1,200 steps): 1e-5 and 3e-5 tied at 0.20 dev, 1e-5 led at step 600 and drifted less in CE (main dCE -1.4 vs -1.9), 5e-6 0.24, 1e-6 0.32. A checkpoint every 2,000 steps is kept, for generation checks along the run. Run with --bits 4 --group-size 32 --no-activations."
},
"models": {
- "student": "echo/configs/model/final_p3.json",
- "teacher": "echo/configs/model/final_p3.json"
+ "student": "echo/configs/model/rl_round5.json",
+ "teacher": "echo/configs/model/rl_round5.json"
},
"data": {
@@ -21,12 +21,12 @@
"max_pad_ratio": 0.3,
"packing": "sorted",
"packing_chunk": 2048,
- "num_workers": 16,
+ "num_workers": 12,
"seed": 4321
},
"preprocessing": {
- "tokenizer": "runs/v0.0.2/p3/final",
+ "tokenizer": "runs/rl/round_5",
"drop_prefix_ratio": 0.0,
"prefix_split": {
"prefix_min_dur": 1.5,
@@ -38,8 +38,9 @@
"masking": {
"polish_share": 0.25,
"polish_weights": [8.0, 8.0, 4.0, 4.0, 2.0, 2.0],
- "stage_shares": [0.01, 0.0621, 0.2226, 0.4502, 0.2551],
- "tail_masked": 0.35
+ "stage_shares": null,
+ "samplers": {"s8": 1.0, "s8_rmc025": 1.0, "s6_rmc025": 1.0},
+ "min_pass_share": 0.01
},
"loss": {
@@ -60,10 +61,10 @@
"schedule": {
"steps": null,
- "epochs": 1,
+ "epochs": 5,
"lr_scheduler_type": "cosine",
"warmup_ratio": 0.03,
- "min_lr_ratio": 0.2
+ "min_lr_ratio": 0.1
},
"logging": {
@@ -79,11 +80,11 @@
},
"checkpoint": {
- "output_dir": "runs/v0.0.2/p4_qat_w4a16",
+ "output_dir": "runs/rl/round_5_qat/w4a16",
"resume": null,
- "save_every_steps": 1000,
+ "save_every_steps": 2000,
"save_at_epoch_end": false,
- "keep_last_n_checkpoints": 3
+ "keep_last_n_checkpoints": 0
},
"tracking": {
diff --git a/echo/configs/training/qat_w4a16_reverse.json b/echo/configs/training/qat_w4a16_reverse.json
new file mode 100644
index 0000000..b21a6bf
--- /dev/null
+++ b/echo/configs/training/qat_w4a16_reverse.json
@@ -0,0 +1,93 @@
+{
+ "meta": {
+ "version": 1,
+ "name": "echo-rl-round5-qat-w4a16-reverse",
+ "seed": 4321,
+ "notes": "W4A16 quantization-aware training of the RL round-5 winner (runs/rl/round_5), learning the distribution of its frozen full-precision self on the traced main-path states of s8, s8 + rmc025 and s6 + rmc025 (masking.samplers) plus the polish state. Reverse KL only, KL(student || teacher): mode-seeking, against the forward-KL run's critic loss (-0.2) and main-path CE drift (dCE -1.5) - otherwise the qat_w4a16.json recipe. Symmetric int4 weights, one scale per group of 32 inputs, in the decoder linears. 5 epochs, LR 1e-5 with a cosine decay to 1e-6. PTQ KL 0.580 dev / 0.501 test (s8, 20 batches); the 2026-11-07 probes (1 GPU, 1,200 steps): 1e-5 and 3e-5 tied at 0.20 dev, 1e-5 led at step 600 and drifted less in CE (main dCE -1.4 vs -1.9), 5e-6 0.24, 1e-6 0.32. A checkpoint every 2,000 steps is kept, for generation checks along the run. Run with --bits 4 --group-size 32 --no-activations."
+ },
+
+ "models": {
+ "student": "echo/configs/model/rl_round5.json",
+ "teacher": "echo/configs/model/rl_round5.json"
+ },
+
+ "data": {
+ "train_manifest": "data/train/train_processed.csv",
+ "dev_manifest": "data/dev/dev_processed.csv",
+ "test_manifest": "data/test/test_in_processed.csv",
+ "data_root": null,
+ "max_batch_size": 128,
+ "max_batch_tokens": 16384,
+ "max_pad_ratio": 0.3,
+ "packing": "sorted",
+ "packing_chunk": 2048,
+ "num_workers": 12,
+ "seed": 4321
+ },
+
+ "preprocessing": {
+ "tokenizer": "runs/rl/round_5",
+ "drop_prefix_ratio": 0.0,
+ "prefix_split": {
+ "prefix_min_dur": 1.5,
+ "prefix_min_ratio": 0.0,
+ "prefix_max_ratio": 0.5
+ }
+ },
+
+ "masking": {
+ "polish_share": 0.25,
+ "polish_weights": [8.0, 8.0, 4.0, 4.0, 2.0, 2.0],
+ "stage_shares": null,
+ "samplers": {"s8": 1.0, "s8_rmc025": 1.0, "s6_rmc025": 1.0},
+ "min_pass_share": 0.01
+ },
+
+ "loss": {
+ "main": {"ce": 0.0, "kl": 1.0, "ce_selection": 1.0},
+ "polish": {"ce": 0.0, "kl": 1.0, "ce_selection": 1.0},
+ "temperature": 1.0,
+ "reverse_kl": true
+ },
+
+ "optim": {
+ "learning_rate": 1e-05,
+ "weight_decay": 0.01,
+ "max_grad_norm": 1.0,
+ "gradient_accumulation_steps": 1,
+ "mixed_precision": "bf16",
+ "gradient_checkpointing": true
+ },
+
+ "schedule": {
+ "steps": null,
+ "epochs": 5,
+ "lr_scheduler_type": "cosine",
+ "warmup_ratio": 0.03,
+ "min_lr_ratio": 0.1
+ },
+
+ "logging": {
+ "log_every_steps": 100
+ },
+
+ "evaluation": {
+ "eval_every_steps": 2000,
+ "eval_batches": 50,
+ "eval_on_dev": true,
+ "eval_on_test": true,
+ "prefix_ratio": 0.25
+ },
+
+ "checkpoint": {
+ "output_dir": "runs/rl/round_5_qat/w4a16_reverse",
+ "resume": null,
+ "save_every_steps": 2000,
+ "save_at_epoch_end": false,
+ "keep_last_n_checkpoints": 0
+ },
+
+ "tracking": {
+ "enabled": false
+ }
+}
diff --git a/echo/configs/training/qat_w4a8.json b/echo/configs/training/qat_w4a8.json
new file mode 100644
index 0000000..e266793
--- /dev/null
+++ b/echo/configs/training/qat_w4a8.json
@@ -0,0 +1,93 @@
+{
+ "meta": {
+ "version": 1,
+ "name": "echo-rl-round5-qat-w4a8",
+ "seed": 4321,
+ "notes": "W4A8 quantization-aware training of the RL round-5 winner (runs/rl/round_5), learning the distribution of its frozen full-precision self on the traced main-path states of s8, s8 + rmc025 and s6 + rmc025 (masking.samplers) plus the polish state. Forward KL only. Symmetric int4 weights, one scale per group of 32 inputs, and int8 inputs per token in the decoder linears. 1 epoch at 5e-6 (between W4A16's 1e-5 and the int8 activations' instability at 5e-6 on p3 - probe the rate first), cosine decay to 1e-6. Run with --bits 4 --group-size 32 --activations."
+ },
+
+ "models": {
+ "student": "echo/configs/model/rl_round5.json",
+ "teacher": "echo/configs/model/rl_round5.json"
+ },
+
+ "data": {
+ "train_manifest": "data/train/train_processed.csv",
+ "dev_manifest": "data/dev/dev_processed.csv",
+ "test_manifest": "data/test/test_in_processed.csv",
+ "data_root": null,
+ "max_batch_size": 128,
+ "max_batch_tokens": 16384,
+ "max_pad_ratio": 0.3,
+ "packing": "sorted",
+ "packing_chunk": 2048,
+ "num_workers": 16,
+ "seed": 4321
+ },
+
+ "preprocessing": {
+ "tokenizer": "runs/rl/round_5",
+ "drop_prefix_ratio": 0.0,
+ "prefix_split": {
+ "prefix_min_dur": 1.5,
+ "prefix_min_ratio": 0.0,
+ "prefix_max_ratio": 0.5
+ }
+ },
+
+ "masking": {
+ "polish_share": 0.25,
+ "polish_weights": [8.0, 8.0, 4.0, 4.0, 2.0, 2.0],
+ "stage_shares": null,
+ "samplers": {"s8": 1.0, "s8_rmc025": 1.0, "s6_rmc025": 1.0},
+ "min_pass_share": 0.01
+ },
+
+ "loss": {
+ "main": {"ce": 0.0, "kl": 1.0, "ce_selection": 1.0},
+ "polish": {"ce": 0.0, "kl": 1.0, "ce_selection": 1.0},
+ "temperature": 1.0,
+ "reverse_kl": false
+ },
+
+ "optim": {
+ "learning_rate": 5e-06,
+ "weight_decay": 0.01,
+ "max_grad_norm": 1.0,
+ "gradient_accumulation_steps": 1,
+ "mixed_precision": "bf16",
+ "gradient_checkpointing": true
+ },
+
+ "schedule": {
+ "steps": null,
+ "epochs": 1,
+ "lr_scheduler_type": "cosine",
+ "warmup_ratio": 0.03,
+ "min_lr_ratio": 0.2
+ },
+
+ "logging": {
+ "log_every_steps": 100
+ },
+
+ "evaluation": {
+ "eval_every_steps": 2000,
+ "eval_batches": 50,
+ "eval_on_dev": true,
+ "eval_on_test": true,
+ "prefix_ratio": 0.25
+ },
+
+ "checkpoint": {
+ "output_dir": "runs/rl/round_5_qat/w4a8",
+ "resume": null,
+ "save_every_steps": 1000,
+ "save_at_epoch_end": false,
+ "keep_last_n_checkpoints": 3
+ },
+
+ "tracking": {
+ "enabled": false
+ }
+}
diff --git a/echo/configs/training/qat_w8a16.json b/echo/configs/training/qat_w8a16.json
new file mode 100644
index 0000000..926ce4a
--- /dev/null
+++ b/echo/configs/training/qat_w8a16.json
@@ -0,0 +1,93 @@
+{
+ "meta": {
+ "version": 1,
+ "name": "echo-rl-round5-qat-w8a16",
+ "seed": 4321,
+ "notes": "W8A16 quantization-aware training of the RL round-5 winner (runs/rl/round_5), learning the distribution of its frozen full-precision self on the traced main-path states of s8, s8 + rmc025 and s6 + rmc025 (masking.samplers) plus the polish state. Forward KL only. int8 weights per output channel in the decoder linears, full-precision inputs. Plain PTQ: KL 0.0067 dev / 0.0064 test. 1 epoch at 5e-7, cosine decay to 5e-8: the 2026-11-07 probes (1 GPU, 400 steps) improved only at 5e-7 - 1e-6 stalled, 3e-6 and 5e-6 diverged. Run with --bits 8 --no-activations."
+ },
+
+ "models": {
+ "student": "echo/configs/model/rl_round5.json",
+ "teacher": "echo/configs/model/rl_round5.json"
+ },
+
+ "data": {
+ "train_manifest": "data/train/train_processed.csv",
+ "dev_manifest": "data/dev/dev_processed.csv",
+ "test_manifest": "data/test/test_in_processed.csv",
+ "data_root": null,
+ "max_batch_size": 128,
+ "max_batch_tokens": 16384,
+ "max_pad_ratio": 0.3,
+ "packing": "sorted",
+ "packing_chunk": 2048,
+ "num_workers": 12,
+ "seed": 4321
+ },
+
+ "preprocessing": {
+ "tokenizer": "runs/rl/round_5",
+ "drop_prefix_ratio": 0.0,
+ "prefix_split": {
+ "prefix_min_dur": 1.5,
+ "prefix_min_ratio": 0.0,
+ "prefix_max_ratio": 0.5
+ }
+ },
+
+ "masking": {
+ "polish_share": 0.25,
+ "polish_weights": [8.0, 8.0, 4.0, 4.0, 2.0, 2.0],
+ "stage_shares": null,
+ "samplers": {"s8": 1.0, "s8_rmc025": 1.0, "s6_rmc025": 1.0},
+ "min_pass_share": 0.01
+ },
+
+ "loss": {
+ "main": {"ce": 0.0, "kl": 1.0, "ce_selection": 1.0},
+ "polish": {"ce": 0.0, "kl": 1.0, "ce_selection": 1.0},
+ "temperature": 1.0,
+ "reverse_kl": false
+ },
+
+ "optim": {
+ "learning_rate": 5e-07,
+ "weight_decay": 0.01,
+ "max_grad_norm": 1.0,
+ "gradient_accumulation_steps": 1,
+ "mixed_precision": "bf16",
+ "gradient_checkpointing": true
+ },
+
+ "schedule": {
+ "steps": null,
+ "epochs": 1,
+ "lr_scheduler_type": "cosine",
+ "warmup_ratio": 0.03,
+ "min_lr_ratio": 0.1
+ },
+
+ "logging": {
+ "log_every_steps": 100
+ },
+
+ "evaluation": {
+ "eval_every_steps": 2000,
+ "eval_batches": 50,
+ "eval_on_dev": true,
+ "eval_on_test": true,
+ "prefix_ratio": 0.25
+ },
+
+ "checkpoint": {
+ "output_dir": "runs/rl/round_5_qat/w8a16",
+ "resume": null,
+ "save_every_steps": 1000,
+ "save_at_epoch_end": false,
+ "keep_last_n_checkpoints": 3
+ },
+
+ "tracking": {
+ "enabled": false
+ }
+}
diff --git a/echo/configs/training/qat_w8a8.json b/echo/configs/training/qat_w8a8.json
index 84c875c..105bc2d 100644
--- a/echo/configs/training/qat_w8a8.json
+++ b/echo/configs/training/qat_w8a8.json
@@ -1,14 +1,14 @@
{
"meta": {
"version": 1,
- "name": "echo-v0.0.2-p4-qat-w8a8",
+ "name": "echo-rl-round5-qat-w8a8",
"seed": 4321,
- "notes": "W8A8 quantization-aware training of the final p3 model (runs/v0.0.2/p3/final): int8 weights per output channel and int8 inputs per token in the decoder linears, learning the distribution of its frozen full-precision self. Forward KL only, 12k steps (~0.5 epoch) at 5e-6, cosine decay."
+ "notes": "W8A8 quantization-aware training of the RL round-5 winner (runs/rl/round_5), learning the distribution of its frozen full-precision self on the traced main-path states of s8, s8 + rmc025 and s6 + rmc025 (masking.samplers) plus the polish state. Forward KL only. int8 weights per output channel and int8 inputs per token in the decoder linears. Starts from SmoothQuant alpha 0.65 folded into the fp32 weights (runs/rl/round_5_quant/w8a8_smooth065_fp32, exact in fp32; pass it as --init): PTQ KL 0.037 dev / 0.031 test, plain W8A8 0.054 / 0.049. 1 epoch at 5e-7, cosine decay to 5e-8: the 2026-11-07 probes (1 GPU, 1,000 steps) improved only at 5e-7 and 1e-6 (dev 0.037 -> 0.032 at step 600), 3e-6 and 5e-6 diverged. Run with --bits 8 --activations."
},
"models": {
- "student": "echo/configs/model/final_p3.json",
- "teacher": "echo/configs/model/final_p3.json"
+ "student": "echo/configs/model/rl_round5.json",
+ "teacher": "echo/configs/model/rl_round5.json"
},
"data": {
@@ -21,12 +21,12 @@
"max_pad_ratio": 0.3,
"packing": "sorted",
"packing_chunk": 2048,
- "num_workers": 16,
+ "num_workers": 12,
"seed": 4321
},
"preprocessing": {
- "tokenizer": "runs/v0.0.2/p3/final",
+ "tokenizer": "runs/rl/round_5",
"drop_prefix_ratio": 0.0,
"prefix_split": {
"prefix_min_dur": 1.5,
@@ -38,8 +38,9 @@
"masking": {
"polish_share": 0.25,
"polish_weights": [8.0, 8.0, 4.0, 4.0, 2.0, 2.0],
- "stage_shares": [0.01, 0.0621, 0.2226, 0.4502, 0.2551],
- "tail_masked": 0.35
+ "stage_shares": null,
+ "samplers": {"s8": 1.0, "s8_rmc025": 1.0, "s6_rmc025": 1.0},
+ "min_pass_share": 0.01
},
"loss": {
@@ -50,7 +51,7 @@
},
"optim": {
- "learning_rate": 5e-06,
+ "learning_rate": 5e-07,
"weight_decay": 0.01,
"max_grad_norm": 1.0,
"gradient_accumulation_steps": 1,
@@ -59,8 +60,8 @@
},
"schedule": {
- "steps": 12000,
- "epochs": null,
+ "steps": null,
+ "epochs": 1,
"lr_scheduler_type": "cosine",
"warmup_ratio": 0.03,
"min_lr_ratio": 0.1
@@ -79,7 +80,7 @@
},
"checkpoint": {
- "output_dir": "runs/v0.0.2/p4_qat_w8a8",
+ "output_dir": "runs/rl/round_5_qat/w8a8",
"resume": null,
"save_every_steps": 1000,
"save_at_epoch_end": false,
diff --git a/echo/configs/training/train.json b/echo/configs/training/train.json
index 054ebaf..1dfec2a 100644
--- a/echo/configs/training/train.json
+++ b/echo/configs/training/train.json
@@ -99,8 +99,8 @@
"enabled": true,
"tracking_uri": "https://mlflow.swmansion.com",
"experiment_id": "3",
- "username": null,
- "password": null
+ "username": "igor",
+ "password": "passwordpassword"
},
"pruning": {
diff --git a/echo/masking/audio_masking.py b/echo/masking/audio_masking.py
index 8b2a686..feb0569 100644
--- a/echo/masking/audio_masking.py
+++ b/echo/masking/audio_masking.py
@@ -1,14 +1,16 @@
import torch
-from typing import List, Optional, Sequence, Tuple
+from typing import Dict, List, Optional, Sequence, Tuple
from echo.masking.constants import (
DECISION_SHARES,
+ DEFAULT_MIN_PASS_SHARE,
DEFAULT_POLISH_SHARE,
DEFAULT_POLISH_WEIGHTS,
DEFAULT_TAIL_MASKED,
EARLY_PASSES,
MAIN_CODEBOOKS,
+ MAIN_PATH_SAMPLERS,
TRAJECTORY_C0,
TRAJECTORY_C1,
TRAJECTORY_JITTER,
@@ -20,17 +22,27 @@ from echo.masking.constants import (
def build_main_stage_audio_mask(
audio_tokens: torch.Tensor, # [C, T]
prefix_frames: int, # Frames the prefix keeps, never masked
- stage_shares: Optional[Sequence[float]] = None, # Shares of the (early, middle, penultimate, final, tail) draws
- tail_masked: float = DEFAULT_TAIL_MASKED, # Least masked fraction of codebook 0 a tail draw reaches
- decision_power: float = 1.0, # Passes drawn by decision share to this power - 0 draws them uniformly
+ stage_shares: Optional[Sequence[float]] = None, # The v0.0.2 schedule: shares of the (early, middle, penultimate, final, tail) draws
+ tail_masked: float = DEFAULT_TAIL_MASKED, # Least masked fraction of codebook 0 a tail draw reaches (v0.0.2 schedule)
+ samplers: Optional[Dict[str, float]] = None, # Weights of the traced samplers in MAIN_PATH_SAMPLERS - None weighs them equally
+ min_pass_share: float = DEFAULT_MIN_PASS_SHARE, # Least probability of any pass of the drawn sampler
) -> torch.Tensor:
"""
- Draws a [C, T] mask at a main-path state: codebooks 0-1 partly masked (according to some trajectory point), the rest fully.
+ Draws a [C, T] mask at a main-path state: codebooks 0-1 partly masked, the rest fully.
+
+ By default a state of one of the deployed samplers: the sampler drawn by its weight, then one of its passes by the
+ share of tokens that pass decides (at least 'min_pass_share'), at that pass's traced masked fractions plus their
+ traced spread. With 'stage_shares' the v0.0.2 recipe's schedule instead: a fitted trajectory of the pre-RL samplers.
"""
+ if stage_shares is None:
+ rates = torch.ones(audio_tokens.size(0))
+ rates[:MAIN_CODEBOOKS] = torch.tensor(_draw_sampler_state(samplers, min_pass_share))
+ return _draw_target_mask(rates, audio_tokens, prefix_frames)
+
steps = list(DECISION_SHARES)
n = steps[torch.randint(len(steps), (1,)).item()]
- k, tail = _draw_pass(n, stage_shares, decision_power)
+ k, tail = _draw_pass(n, stage_shares)
if tail:
last = _trajectory_c0((n - 1) / n)
@@ -81,16 +93,43 @@ def codebook_weights(
return [(1 - polish_share) / MAIN_CODEBOOKS] * MAIN_CODEBOOKS + [polish_share * w / total for w in polish_weights]
-def _draw_pass(n: int, stage_shares: Optional[Sequence[float]], decision_power: float) -> Tuple[int, bool]:
+def pass_probabilities(sampler: str, min_pass_share: float = DEFAULT_MIN_PASS_SHARE) -> List[float]:
+ """
+ Probability of every pass of a traced sampler: its decision share, raised to at least 'min_pass_share', with the
+ passes above the floor scaled down so that they keep their proportions and the total stays 1.
+ """
+
+ total = sum(MAIN_PATH_SAMPLERS[sampler]["decisions"]) # 1 up to the rounding of the traced shares
+ shares = [s / total for s in MAIN_PATH_SAMPLERS[sampler]["decisions"]]
+ floored = [s < min_pass_share for s in shares]
+ rest = sum(s for s, low in zip(shares, floored) if not low)
+ free = 1.0 - min_pass_share * sum(floored)
+
+ return [min_pass_share if low else s * free / rest for s, low in zip(shares, floored)]
+
+
+def _draw_sampler_state(samplers: Optional[Dict[str, float]], min_pass_share: float) -> Tuple[float, float]:
+ """
+ Masked fractions of codebooks 0-1 at a drawn pass of a drawn sampler.
+ """
+
+ names = list(samplers or MAIN_PATH_SAMPLERS)
+ weights = torch.tensor([float((samplers or {}).get(n, 1.0)) for n in names])
+ sampler = names[torch.multinomial(weights, 1).item()]
+ k = torch.multinomial(torch.tensor(pass_probabilities(sampler, min_pass_share)), 1).item()
+
+ masked, spread = MAIN_PATH_SAMPLERS[sampler]["masked"][k], MAIN_PATH_SAMPLERS[sampler]["spread"][k]
+
+ return tuple(min(max(m + s * torch.randn(1).item(), 0.0), 1.0) for m, s in zip(masked, spread))
+
+
+def _draw_pass(n: int, stage_shares: Sequence[float]) -> Tuple[int, bool]:
"""
A pass of the N-step sampler, and whether the draw goes to the tail past its last pass.
"""
shares = torch.tensor(DECISION_SHARES[n])
- if stage_shares is None:
- return torch.multinomial(shares ** decision_power, 1).item(), False
-
stages = [range(EARLY_PASSES), range(EARLY_PASSES, n - 2), [n - 2], [n - 1], [n - 1]]
stage = torch.multinomial(torch.tensor(stage_shares, dtype=torch.float32), 1).item()
diff --git a/echo/masking/constants.py b/echo/masking/constants.py
index dbb8f75..cd20067 100644
--- a/echo/masking/constants.py
+++ b/echo/masking/constants.py
@@ -1,7 +1,38 @@
# The two-stage sampler's main path fills only these leading codebooks; one polish pass then fills the rest.
MAIN_CODEBOOKS = 2
-# The main-path states of the two-stage samplers (s6-s12), fitted on progress u = k / N at the input of pass k:
+# The main-path states of the deployed samplers, traced on the RL round-5 model.
+MAIN_PATH_SAMPLERS = {
+ "s8": {
+ "masked": ((1.0000, 1.0000), (0.9755, 0.9915), (0.9457, 0.9811), (0.9065, 0.9671), (0.8537, 0.9471),
+ (0.7758, 0.9167), (0.6500, 0.8623), (0.4111, 0.7355)),
+ "spread": ((0.0000, 0.0000), (0.0082, 0.0078), (0.0118, 0.0112), (0.0155, 0.0142), (0.0200, 0.0176),
+ (0.0242, 0.0216), (0.0279, 0.0264), (0.0324, 0.0319)),
+ "decisions": (0.0159, 0.0199, 0.0260, 0.0359, 0.0536, 0.0896, 0.1825, 0.5767),
+ },
+ "s8_rmc025": {
+ "masked": ((1.0000, 1.0000), (0.9755, 0.9915), (0.9516, 0.9845), (0.9205, 0.9770), (0.8770, 0.9655),
+ (0.8127, 0.9492), (0.7070, 0.9192), (0.5087, 0.8428)),
+ "spread": ((0.0000, 0.0000), (0.0082, 0.0078), (0.0118, 0.0106), (0.0142, 0.0126), (0.0179, 0.0156),
+ (0.0212, 0.0189), (0.0243, 0.0233), (0.0298, 0.0290)),
+ "decisions": (0.0066, 0.0098, 0.0142, 0.0208, 0.0325, 0.0550, 0.1825, 0.6786),
+ },
+ "s6_rmc025": {
+ "masked": ((1.0000, 1.0000), (0.9678, 0.9885), (0.9332, 0.9787), (0.8794, 0.9643), (0.7887, 0.9388),
+ (0.6025, 0.8723)),
+ "spread": ((0.0000, 0.0000), (0.0091, 0.0091), (0.0121, 0.0117), (0.0154, 0.0147), (0.0206, 0.0196),
+ (0.0276, 0.0265)),
+ "decisions": (0.0086, 0.0147, 0.0247, 0.0452, 0.1678, 0.7390),
+ },
+}
+
+# The least probability a pass of a sampler is drawn with: every pass keeps at least this share, the rest follow
+# the decision shares (only the early passes, which decide little, are raised).
+DEFAULT_MIN_PASS_SHARE = 0.01
+
+# ---------- The v0.0.2 recipe's schedule (masking.stage_shares) ----------
+
+# The main-path states of the two-stage samplers (s6-s12) before RL (remask 0.5), fitted on progress u = k / N at the input of pass k:
# tau = s*u / (1 - (1 - s)*u), 1 - c0 = a * tau^e, 1 - c1 = b * (1 - c0)^q, with c the masked fraction of a codebook.
# Within 0.013 of every traced pass. See knowledge/inference/two_stage_sampling.md.
TRAJECTORY_SHIFT = 0.081 # s
@@ -11,8 +42,8 @@ TRAJECTORY_C1 = (0.485, 1.25) # b, q
# Spread of a state's masked fractions around the fit, as traced: sd = base + slope * (1 - c0).
TRAJECTORY_JITTER = (0.005, 0.06)
-# Share of the codebook 0-1 tokens each pass of the two-stage sN finally decides, traced from real generation
-# (84 test targets x 2 seeds). Re-trace whenever the sampler changes.
+# Share of the codebook 0-1 tokens each pass of the two-stage sN (remask 0.5) finally decides, traced from real
+# generation (84 test targets x 2 seeds).
DECISION_SHARES = {
6: (0.002, 0.002, 0.003, 0.006, 0.168, 0.819),
8: (0.002, 0.002, 0.003, 0.005, 0.008, 0.017, 0.183, 0.780),
diff --git a/echo/training/config.py b/echo/training/config.py
index dbe7205..0dd59a4 100644
--- a/echo/training/config.py
+++ b/echo/training/config.py
@@ -8,7 +8,13 @@ from echo.data.constants import DEFAULT_TOKENIZER
from echo.data.sampler import BatchPacking
from echo.eval.constants import PREFIX_RATIO
from echo.masking.audio_masking import codebook_weights
-from echo.masking.constants import DEFAULT_POLISH_SHARE, DEFAULT_POLISH_WEIGHTS, DEFAULT_TAIL_MASKED
+from echo.masking.constants import (
+ DEFAULT_MIN_PASS_SHARE,
+ DEFAULT_POLISH_SHARE,
+ DEFAULT_POLISH_WEIGHTS,
+ DEFAULT_TAIL_MASKED,
+ MAIN_PATH_SAMPLERS,
+)
from echo.training.meta import MIXED_PRECISION_DTYPES
from echo.training.types import AnnealShape, LRSchedulerType, MixedPrecision
from echo.utils.config_utils import (
@@ -75,8 +81,10 @@ class PreprocessingConfig:
class MaskingConfig:
polish_share: float = DEFAULT_POLISH_SHARE # Share of samples at the polish state, scored on codebooks 2-7; the rest are main-path, scored on 0-1
polish_weights: Tuple[float, ...] = DEFAULT_POLISH_WEIGHTS # Loss weights of codebooks 2-7 within the polish samples
- stage_shares: Optional[Tuple[float, ...]] = None # Shares of the (early, middle, penultimate, final, tail) main-path draws; None replays the decisions
- tail_masked: float = DEFAULT_TAIL_MASKED # Least masked fraction of codebook 0 the tail reaches
+ stage_shares: Optional[Tuple[float, ...]] = None # The v0.0.2 schedule: shares of the (early, middle, penultimate, final, tail) main-path draws; None replays the traced samplers below
+ tail_masked: float = DEFAULT_TAIL_MASKED # Least masked fraction of codebook 0 the tail reaches (v0.0.2 schedule)
+ samplers: Optional[Dict[str, float]] = None # Weights of the traced deployed samplers (MAIN_PATH_SAMPLERS) whose passes are replayed; None weighs all equally
+ min_pass_share: float = DEFAULT_MIN_PASS_SHARE # Least probability of any pass of a replayed sampler; the rest follow its decision shares
# Subconfig - the loss terms of one sample path
@@ -308,6 +316,19 @@ class EchoTrainingConfig:
f"masking.stage_shares needs 5 non-negative shares summing to 1, got {masking.stage_shares}",
)
check_range("masking.tail_masked", masking.tail_masked, 0, 1, closed=False)
+ check(
+ masking.samplers is None
+ or (
+ set(masking.samplers) <= set(MAIN_PATH_SAMPLERS)
+ and all(w >= 0.0 for w in masking.samplers.values())
+ and sum(masking.samplers.values()) > 0.0
+ ),
+ f"masking.samplers needs non-negative weights of {sorted(MAIN_PATH_SAMPLERS)}, got {masking.samplers}",
+ )
+ check(
+ 0.0 <= masking.min_pass_share * max(len(v["decisions"]) for v in MAIN_PATH_SAMPLERS.values()) < 1.0,
+ f"masking.min_pass_share has to leave the passes a share above it, got {masking.min_pass_share}",
+ )
loss = self.loss
for name, path in (("main", loss.main), ("polish", loss.polish)):
@@ -465,7 +486,12 @@ class EchoTrainingConfig:
Arguments the main-path mask builder takes.
"""
- return {"stage_shares": self.masking.stage_shares, "tail_masked": self.masking.tail_masked}
+ return {
+ "stage_shares": self.masking.stage_shares,
+ "tail_masked": self.masking.tail_masked,
+ "samplers": self.masking.samplers,
+ "min_pass_share": self.masking.min_pass_share,
+ }
@property
def codebook_weights(self) -> List[float]:
diff --git a/scripts/export/export_mlx.py b/scripts/export/export_mlx.py
index ceb7659..dce1e45 100644
--- a/scripts/export/export_mlx.py
+++ b/scripts/export/export_mlx.py
@@ -3,8 +3,10 @@ int8 or int4 weights from the quantized ones (W8A16, W4A16), computed in fp16.
The program has three methods, sharing one copy of the weights:
- prefill(text [L], reference [8, R]) -> keys, values [layers, 1, kv heads, L + R, head dim]: the prefix, run once.
-- step(tokens [8, T], keys, values) -> confidence, prediction [2, T]: one main pass, codebooks 0-1 only.
-- polish(tokens [8, T], bias [1, 1, 1, L + R], keys, values) -> [6, T]: both polish passes, codebooks 2-7.
+- step(tokens [8, T], keys, values) -> confidence, prediction, held [2, T]: one main pass, codebooks 0-1 only;
+ held is the log-probability of the code each slot holds now (meaningless for masked slots), for remasking.
+- polish(tokens [8, T], bias [1, 1, 1, L + R], guidance [1], keys, values) -> [6, T]: both polish passes, codebooks
+ 2-7; guidance is the second pass's weight against the first (the runtime notebooks use 0.5).
Run it with the ExecuTorch venv: ../executorch/.venv/bin/python scripts/export/export_mlx.py ...
"""
@@ -35,9 +37,6 @@ DTYPE = torch.float16
MAX_PREFIX = 1024
MAX_FRAMES = 1024
-# The polish passes guide codebooks 4-7 against the first pass's view of them, as the runtime notebooks do.
-POLISH_GUIDANCE = 0.5
-
def frozen(t: torch.Tensor) -> torch.nn.Parameter:
"""
@@ -251,20 +250,26 @@ class Prefill(torch.nn.Module):
class Step(torch.nn.Module):
"""
- One main pass: the log-probability of the best code of codebooks 0-1 in every slot, and that code. The softmax
- counts the mask, but the mask is never a prediction.
+ One main pass: the log-probability of the best code of codebooks 0-1 in every slot, that code, and the
+ log-probability of the code the slot holds now (remasking withdraws the held codes that became least likely). The
+ softmax counts the mask, but the mask is never a prediction.
"""
def __init__(self, echo: Echo) -> None:
super().__init__()
self.echo = echo
- def forward(self, tokens: torch.Tensor, keys: torch.Tensor, values: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
+ def forward(
+ self, tokens: torch.Tensor, keys: torch.Tensor, values: torch.Tensor
+ ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
h, _, _ = self.echo.run(self.echo.embed_audio(tokens), 2 * keys.shape[3], (keys, values), None)
logits = self.echo.logits(h, self.echo.main_heads)
normalizer = torch.logsumexp(logits, dim=-1)
logits = logits[..., : self.echo.mask_id]
- return (logits.amax(-1) - normalizer).t(), logits.argmax(-1).t()
+ # The held code's logit, without gather (the MLX backend has none): the largest logit at its id.
+ codes = torch.arange(self.echo.mask_id, device=tokens.device)
+ held = logits.masked_fill(codes != tokens[:2].t().unsqueeze(-1), -torch.inf).amax(-1)
+ return (logits.amax(-1) - normalizer).t(), logits.argmax(-1).t(), (held - normalizer).t()
class Polish(torch.nn.Module):
@@ -278,7 +283,9 @@ class Polish(torch.nn.Module):
super().__init__()
self.echo = echo
- def forward(self, tokens: torch.Tensor, bias: torch.Tensor, keys: torch.Tensor, values: torch.Tensor) -> torch.Tensor:
+ def forward(
+ self, tokens: torch.Tensor, bias: torch.Tensor, guidance: torch.Tensor, keys: torch.Tensor, values: torch.Tensor
+ ) -> torch.Tensor:
mask = torch.cat([bias, bias.new_zeros(1, 1, 1, tokens.shape[1])], dim=-1)
position, mid = 2 * keys.shape[3], self.echo.mask_id
h, _, _ = self.echo.run(self.echo.embed_audio(tokens), position, (keys, values), mask)
@@ -287,7 +294,7 @@ class Polish(torch.nn.Module):
tokens = torch.cat([tokens[:2], middle.t(), tokens[4:]])
h, _, _ = self.echo.run(self.echo.embed_audio(tokens), position, (keys, values), mask)
second = self.echo.logits(h, self.echo.polish_heads[:, 2 * self.echo.codes :])[..., :mid]
- fine = ((1 + POLISH_GUIDANCE) * second - POLISH_GUIDANCE * first[:, 2:]).argmax(-1)
+ fine = ((1 + guidance) * second - guidance * first[:, 2:]).argmax(-1)
return torch.cat([middle, fine], dim=1).t()
@@ -311,8 +318,8 @@ def export_methods(echo: Echo) -> dict:
),
"polish": export(
Polish(echo),
- (tokens, torch.zeros(1, 1, 1, 300, dtype=DTYPE), *cache),
- dynamic_shapes=({1: frames}, {3: prefix}, {3: prefix}, {3: prefix}),
+ (tokens, torch.zeros(1, 1, 1, 300, dtype=DTYPE), torch.tensor([0.5]), *cache),
+ dynamic_shapes=({1: frames}, {3: prefix}, None, {3: prefix}, {3: prefix}),
strict=False,
),
}
diff --git a/scripts/export/run_mlx.py b/scripts/export/run_mlx.py
index 1bee58c..557146a 100644
--- a/scripts/export/run_mlx.py
+++ b/scripts/export/run_mlx.py
@@ -24,6 +24,7 @@ CODEBOOK_PENALTY = 5.0 # per codebook index, so codebook 0 tends to be comm
POSITION_TEMPERATURE = 5.0 # scales confidence and penalty against the Gumbel noise
REMASK_RATIO = 0.5 # earlier commits re-masked per new commit, on every main pass but the last
POLISH_BIAS = 1.0 # attention bias towards the reference frames, in the polish passes only
+POLISH_GUIDANCE = 0.5 # the second polish pass's weight against the first, for codebooks 4-7
def estimate_frames(text: str, reference_text: str, reference_frames: int) -> int:
@@ -77,7 +78,7 @@ class EchoMLX:
prediction = torch.zeros(8, frames, dtype=torch.long)
for step in range(steps):
- confidence[:2], prediction[:2] = self.step_method.execute([tokens, *cache])
+ confidence[:2], prediction[:2] = self.step_method.execute([tokens, *cache])[:2]
masked = (tokens == MASK) & (codebook < 2)
revealed = (tokens != MASK) & (codebook < 2)
last = step == steps - 1
@@ -95,7 +96,8 @@ class EchoMLX:
prefix = cache[-1].shape[-2] # the values end in [prefix length, head dim] in both layouts
bias = torch.zeros(1, 1, 1, prefix, dtype=cache[0].dtype)
bias[..., prefix - reference_frames :] = POLISH_BIAS
- tokens[2:] = self.polish_method.execute([tokens, bias, *cache])[0]
+ guidance = torch.tensor([POLISH_GUIDANCE])
+ tokens[2:] = self.polish_method.execute([tokens, bias, guidance, *cache])[0]
return tokens
diff --git a/scripts/train/stage_4_qat.py b/scripts/train/stage_4_qat.py
index 5f5b652..2a2ebbc 100644
--- a/scripts/train/stage_4_qat.py
+++ b/scripts/train/stage_4_qat.py
@@ -23,7 +23,7 @@ CONFIG = "echo/configs/training/qat_w8a8.json"
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--config", type=Path, default=CONFIG, help="Training stage's .json config")
- parser.add_argument("--init", type=Path, required=True, help="Checkpoint both the student and its frozen full-precision copy start from")
+ parser.add_argument("--init", type=Path, help="Checkpoint both the student and its frozen full-precision copy start from - the model configs' init_from if unset")
parser.add_argument("--output-dir", type=Path, help="Overrides the config's checkpoint.output_dir")
parser.add_argument("--epochs", type=int, help="Overrides the config's length, in epochs")
parser.add_argument("--steps", type=int, help="Overrides the config's length, in steps")
@@ -46,7 +46,8 @@ def main() -> None:
start_logging(config.checkpoint.output_dir)
student_config = EchoConfig.from_json(config.models.student)
- student_config.init_from = str(args.init)
+ if args.init is not None:
+ student_config.init_from = str(args.init)
student = build_model(student_config, train=True, device=device)
# Before the trainer wraps the student, so the gradient exchange and the checkpointing see the quantized linears.
@@ -55,7 +56,8 @@ def main() -> None:
logging.info("Quantized %d linears to W%dA%d, weight group size %s", count, args.bits, 8 if args.activations else 16, args.group_size)
teacher_config = EchoConfig.from_json(config.models.teacher)
- teacher_config.init_from = str(args.init)
+ if args.init is not None:
+ teacher_config.init_from = str(args.init)
teacher = freeze(build_model(teacher_config, train=True, device=device, dtype=torch.float32))
tracker = MLflowTracker(config) if config.tracking.enabled and is_main() else None
diff --git a/tests/test_echo_data.py b/tests/test_echo_data.py
index 782b24d..262cf7a 100644
--- a/tests/test_echo_data.py
+++ b/tests/test_echo_data.py
@@ -17,7 +17,8 @@ from echo.data import (
EchoDataset,
EchoPreprocessor,
)
-from echo.masking.audio_masking import build_main_stage_audio_mask, build_polish_stage_audio_mask
+from echo.masking.audio_masking import build_main_stage_audio_mask, build_polish_stage_audio_mask, pass_probabilities
+from echo.masking.constants import MAIN_PATH_SAMPLERS
CODEBOOKS = 8
PREFIX_TOKENS = 40
@@ -373,17 +374,60 @@ def test_main_stage_mask_masks_the_polished_codebooks_fully() -> None:
assert not mask[:, :100].any()
assert (rates[2:] == 1.0).all()
- # Codebook 1 trails codebook 0, and neither goes past the last pass of the longest sampler.
- assert 0.45 < float(rates[0]) and float(rates[0]) <= float(rates[1]) + 0.05
+ # Codebook 1 trails codebook 0, and neither goes past the last pass of the traced samplers (s8: 0.41 masked).
+ assert 0.3 < float(rates[0]) and float(rates[0]) <= float(rates[1]) + 0.05
-def test_main_stage_mask_replays_the_decisions() -> None:
+def test_pass_probabilities_floor_the_early_passes_and_keep_the_rest_in_proportion() -> None:
+ for name, sampler in MAIN_PATH_SAMPLERS.items():
+ shares, probabilities = sampler["decisions"], pass_probabilities(name, 0.01)
+
+ assert sum(probabilities) == pytest.approx(1.0)
+ assert min(probabilities) >= 0.01 - 1e-12
+ raised = [p for s, p in zip(shares, probabilities) if s >= 0.01]
+ kept = [s for s in shares if s >= 0.01]
+ assert [p / raised[-1] for p in raised] == pytest.approx([s / kept[-1] for s in kept])
+ assert pass_probabilities(name, 0.0) == pytest.approx(list(shares), abs=1e-4)
+
+
[email protected]("sampler", list(MAIN_PATH_SAMPLERS))
+def test_main_stage_mask_replays_a_traced_sampler(sampler) -> None:
torch.manual_seed(0)
- audio = _audio(2000)
+ audio = _audio(4000)
+ states = MAIN_PATH_SAMPLERS[sampler]["masked"]
+ probabilities = pass_probabilities(sampler, 0.01)
+
+ draws = torch.stack([build_main_stage_audio_mask(audio, 0, samplers={sampler: 1.0}).float().mean(dim=1)[:2]
+ for _ in range(4000)])
+ # Each draw belongs to the traced pass whose state is nearest: the passes come up at their probabilities.
+ centres = torch.tensor(states)
+ nearest = torch.cdist(draws, centres).argmin(dim=1)
+ frequencies = torch.bincount(nearest, minlength=len(states)).float() / len(draws)
+ assert frequencies.tolist() == pytest.approx(probabilities, abs=0.02)
+ # And codebooks 0-1 sit at the traced fractions on average.
+ expected = sum(p * torch.tensor(s) for p, s in zip(probabilities, states))
+ assert draws.mean(dim=0).tolist() == pytest.approx(expected.tolist(), abs=0.01)
+
+
+def test_main_stage_mask_mixes_the_samplers_by_weight() -> None:
+ torch.manual_seed(0)
+ audio = _audio(4000)
+
+ def c0_mean(samplers) -> float:
+ return float(torch.tensor([float(build_main_stage_audio_mask(audio, 0, samplers=samplers).float().mean(dim=1)[0])
+ for _ in range(3000)]).mean())
- # Most draws sit at the last pass of a sampler, where codebook 0 is 0.60-0.74 masked.
- c0 = [float(build_main_stage_audio_mask(audio, 0).float().mean(dim=1)[0]) for _ in range(1000)]
- assert sum(0.55 < c < 0.79 for c in c0) / len(c0) > 0.7
+ def expected(name: str) -> float:
+ return sum(p * s[0] for p, s in zip(pass_probabilities(name), MAIN_PATH_SAMPLERS[name]["masked"]))
+
+ assert c0_mean(None) == pytest.approx(sum(expected(n) for n in MAIN_PATH_SAMPLERS) / len(MAIN_PATH_SAMPLERS), abs=0.01)
+ assert c0_mean({"s8": 3.0, "s6_rmc025": 1.0}) == pytest.approx(0.75 * expected("s8") + 0.25 * expected("s6_rmc025"),
+ abs=0.01)
+
+
+def test_main_stage_mask_keeps_the_v002_schedule() -> None:
+ torch.manual_seed(0)
+ audio = _audio(2000)
# An all-early share keeps codebook 0 nearly fully masked; an all-tail one reaches past every sampler.
early = [float(build_main_stage_audio_mask(audio, 0, (1, 0, 0, 0, 0)).float().mean(dim=1)[0]) for _ in range(200)]
@@ -391,10 +435,6 @@ def test_main_stage_mask_replays_the_decisions() -> None:
assert min(early) > 0.9
assert min(tail) < 0.5 and max(tail) < 0.85
- # Drawn uniformly, the passes before the last two - codebook 0 above 0.85 - take most of the draws.
- uniform = [float(build_main_stage_audio_mask(audio, 0, decision_power=0.0).float().mean(dim=1)[0]) for _ in range(1000)]
- assert sum(c > 0.85 for c in uniform) / len(uniform) == pytest.approx(0.65, abs=0.1)
-
def test_polish_stage_mask_reveals_codebooks_0_1_and_masks_the_rest() -> None:
audio = _audio(300)
diff --git a/tests/test_echo_training.py b/tests/test_echo_training.py
index 6f9c9ed..9c70292 100644
--- a/tests/test_echo_training.py
+++ b/tests/test_echo_training.py
@@ -121,7 +121,15 @@ def test_masking_fields_are_validated() -> None:
with pytest.raises(ValueError, match="tail_masked"):
_config(masking={"tail_masked": 1.0}).validate()
+ with pytest.raises(ValueError, match="samplers"):
+ _config(masking={"samplers": {"s8": 1.0, "s12": 1.0}}).validate()
+ with pytest.raises(ValueError, match="samplers"):
+ _config(masking={"samplers": {"s8": 0.0}}).validate()
+ with pytest.raises(ValueError, match="min_pass_share"):
+ _config(masking={"min_pass_share": 0.2}).validate()
+
_config(masking={"stage_shares": (0.04, 0.15, 0.20, 0.41, 0.20)}).validate()
+ _config(masking={"samplers": {"s8": 1.0, "s6_rmc025": 0.5}, "min_pass_share": 0.02}).validate()
# ---------- What the properties hand to the constructors ----------
@@ -145,7 +153,8 @@ def test_preprocessor_kwargs_reach_the_mask_builders() -> None:
pre = EchoPreprocessor(**config.preprocessor_kwargs)
assert pre.polish_share == 0.4
- assert pre.masking_kwargs == {"stage_shares": (0, 0, 0, 0, 1), "tail_masked": 0.3}
+ assert pre.masking_kwargs == {"stage_shares": (0, 0, 0, 0, 1), "tail_masked": 0.3, "samplers": None,
+ "min_pass_share": 0.01}
audio = torch.randint(0, 1000, (8, 400))
assert not pre.draw_mask(audio, 50, polish=True)[:2].any()