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.
updates
HenryNdubuakuafb1a28dd38a
diff --git a/src/calibrate.py b/src/calibrate.pyindex 1107b11..c860db4 100644--- a/src/calibrate.py+++ b/src/calibrate.py@@ -201,11 +201,11 @@ def _train_step_inner(model, tx, is_conf_param, params, opt_state, src, enc_seg_"""Inner training step — separated for pmap with axis_name."""def loss_fn(params):src_mask = make_packing_mask(enc_seg_ids)- encoder_out = model.apply(+ encoder_out, enc_mask = model.apply({"params": params}, src, src_mask=src_mask, method="encode_text",)pred = model.apply(- {"params": params}, encoder_out, src_mask,+ {"params": params}, encoder_out, enc_mask,method="predict_confidence",)return jnp.mean((pred - targets) ** 2)@@ -241,11 +241,11 @@ def evaluate_confidence(model, params, train_data, confidence_labels, perplexiti@jax.pmapdef predict_step(params, src, enc_seg_ids):src_mask = make_packing_mask(enc_seg_ids)- encoder_out = model.apply(+ encoder_out, enc_mask = model.apply({"params": params}, src, src_mask=src_mask, method="encode_text",)return model.apply(- {"params": params}, encoder_out, src_mask,+ {"params": params}, encoder_out, enc_mask,method="predict_confidence",)diff --git a/src/cli.py b/src/cli.pyindex b6c638c..44400e7 100644--- a/src/cli.py+++ b/src/cli.py@@ -22,8 +22,8 @@ def main():p.add_argument("--d-model", type=int, default=512)p.add_argument("--num-heads", type=int, default=8)p.add_argument("--num-kv-heads", type=int, default=4)- p.add_argument("--num-layers", type=int, default=12)- p.add_argument("--num-dec-layers", type=int, default=12)+ p.add_argument("--num-layers", type=int, default=10)+ p.add_argument("--num-dec-layers", type=int, default=10)p.add_argument("--max-enc-len", type=int, default=DEFAULT_MAX_ENC_LEN)p.add_argument("--max-dec-len", type=int, default=DEFAULT_MAX_DEC_LEN)p.add_argument("--max-samples", type=int, default=None)diff --git a/src/eval.py b/src/eval.pyindex 8ec3b69..e3caade 100644--- a/src/eval.py+++ b/src/eval.py@@ -277,8 +277,12 @@ def benchmark_tool_calls(model, params, tokenizer, num_samples=200, max_gen_len=if ref_is_empty and pred_is_empty:exact_match += 1- elif not ref_is_empty and not pred_is_empty and json.dumps(pred_calls, sort_keys=True) == json.dumps(ref_calls, sort_keys=True):- exact_match += 1+ elif not ref_is_empty and not pred_is_empty:+ # Order-independent comparison: sort calls by their canonical key+ ref_sorted = sorted([call_key(c) for c in ref_calls if call_key(c)])+ pred_sorted = sorted([call_key(c) for c in pred_calls if call_key(c)])+ if ref_sorted == pred_sorted and len(ref_sorted) == len(ref_calls) and len(pred_sorted) == len(pred_calls):+ exact_match += 1ref_name_set = {c["name"] for c in ref_calls if isinstance(c, dict) and "name" in c}pred_name_set = {c["name"] for c in pred_calls if isinstance(c, dict) and "name" in c}@@ -332,7 +336,9 @@ def benchmark_tool_calls(model, params, tokenizer, num_samples=200, max_gen_len=# Diagnose failures for this exampleis_exact = (ref_is_empty and pred_is_empty) or (not ref_is_empty and not pred_is_empty- and json.dumps(pred_calls, sort_keys=True) == json.dumps(ref_calls, sort_keys=True)+ and sorted([call_key(c) for c in ref_calls if call_key(c)])+ == sorted([call_key(c) for c in pred_calls if call_key(c)])+ and len(ref_calls) == len(pred_calls))if not is_exact and len(failures) < 50:reasons = []diff --git a/src/split_dataset.py b/src/split_dataset.pyindex 79e38d7..723bf1c 100644--- a/src/split_dataset.py+++ b/src/split_dataset.py@@ -13,14 +13,19 @@ import shutilimport tempfileHF_DATASET_REPO = "Cactus-Compute/tool-calls"-VAL_PER_SOURCE = 2000+VAL_PER_SOURCE = {+ "gemini-3.1-flash-lite": 5000,+ "xlam": 2500,+ "xlam-translated": 2500,+}SEED = 42def main(args=None):- val_per_source = VAL_PER_SOURCE+ val_per_source = dict(VAL_PER_SOURCE)if args is not None and getattr(args, "val_per_source", None) is not None:- val_per_source = args.val_per_source+ # CLI override applies uniformly to all sources+ val_per_source = {k: args.val_per_source for k in val_per_source}print(f"Downloading full dataset from {HF_DATASET_REPO} (train split only)...")from .data import download_hf_split@@ -46,7 +51,7 @@ def main(args=None):val_indices = []for src, indices in sorted(source_indices.items()):rng.shuffle(indices)- take = min(val_per_source, len(indices))+ take = min(val_per_source.get(src, 0), len(indices))val_indices.extend(indices[:take])print(f" {src}: taking {take} for validation")diff --git a/src/train.py b/src/train.pyindex 681ef8b..14c6dcf 100644--- a/src/train.py+++ b/src/train.py@@ -1037,9 +1037,12 @@ def train(args):if ref_is_empty and pred_is_empty:m_exact += 1pc["exact"] += 1- elif not ref_is_empty and not pred_is_empty and _json_mod.dumps(pred_calls, sort_keys=True) == _json_mod.dumps(ref_calls, sort_keys=True):- m_exact += 1- pc["exact"] += 1+ elif not ref_is_empty and not pred_is_empty:+ ref_sorted = sorted([_call_key(c) for c in ref_calls if _call_key(c)])+ pred_sorted = sorted([_call_key(c) for c in pred_calls if _call_key(c)])+ if ref_sorted == pred_sorted and len(ref_sorted) == len(ref_calls) and len(pred_sorted) == len(pred_calls):+ m_exact += 1+ pc["exact"] += 1ref_names = {c["name"] for c in ref_calls if isinstance(c, dict) and "name" in c}pred_names = {c["name"] for c in pred_calls if isinstance(c, dict) and "name" in c}m_name_tp += len(pred_names & ref_names)@@ -1095,7 +1098,9 @@ def train(args):# Failure diagnosisis_exact = (ref_is_empty and pred_is_empty) or (not ref_is_empty and not pred_is_empty- and _json_mod.dumps(pred_calls, sort_keys=True) == _json_mod.dumps(ref_calls, sort_keys=True)+ and sorted([_call_key(c) for c in ref_calls if _call_key(c)])+ == sorted([_call_key(c) for c in pred_calls if _call_key(c)])+ and len(ref_calls) == len(pred_calls))if not is_exact and len(m_failures) < 30:reasons = []