Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(notebooks): clamp fit_one_temp to common TEMP_MIN and TEMP_MAX bounds
Sarthak Pandey1580c398df46
diff --git a/notebooks/laya_finetune_typed_decisions_2xT4_kaggle.ipynb b/notebooks/laya_finetune_typed_decisions_2xT4_kaggle.ipynbindex 33ee17d8..29ae152d 100644--- a/notebooks/laya_finetune_typed_decisions_2xT4_kaggle.ipynb+++ b/notebooks/laya_finetune_typed_decisions_2xT4_kaggle.ipynb@@ -4,7 +4,7 @@"cell_type": "markdown","metadata": {},"source": [- "# Fine-Tuning Laya on `LocalLLaMA/typed-decisions` (Kaggle GPU T4 \u00d72 DDP)\n",+ "# Fine-Tuning Laya on `LocalLLaMA/typed-decisions` (Kaggle GPU T4 ×2 DDP)\n","\n","[](https://pypi.org/project/laya/)\n","[](https://huggingface.co/convaiinnovations/laya)\n",@@ -14,7 +14,7 @@"\n","---\n","\n",- "### \u26a0\ufe0f Kaggle Notebook Settings:\n",+ "### ⚠️ Kaggle Notebook Settings:\n","In the right-hand sidebar panel under **Notebook options**:\n","* **Accelerator:** Select **`GPU T4 x2`** (ensure both GPUs are allocated)\n","* **Internet:** Set to **`On`**\n",@@ -171,7 +171,7 @@"from torch.nn.parallel import DistributedDataParallel as DDP\n","from safetensors.torch import load_file, save_file\n","from transformers import AutoTokenizer\n",- "from laya.common import build_model, proper_reward, QTYPES\n",+ "from laya.common import build_model, proper_reward, QTYPES, TEMP_MIN, TEMP_MAX\n","\n","def collate_train_batch(items, pad_id):\n"," n, L = len(items), max(len(it[\"ids\"]) for it in items)\n",@@ -215,7 +215,7 @@" loss.backward()\n"," return loss\n"," opt.step(closure)\n",- " return float(torch.clamp(log_t.exp(), 0.1, 10.0).item())\n",+ " return float(torch.clamp(log_t.exp(), TEMP_MIN, TEMP_MAX).item())\n","\n","def main():\n"," dist.init_process_group(\"nccl\")\n",@@ -431,7 +431,7 @@" dist.destroy_process_group()\n","\n","if __name__ == \"__main__\":\n",- " main()\n"+ " main()"],"execution_count": null,"outputs": []diff --git a/tests/test_calibration_persistence.py b/tests/test_calibration_persistence.pyindex 0b6292ac..c2187965 100644--- a/tests/test_calibration_persistence.py+++ b/tests/test_calibration_persistence.py@@ -25,7 +25,7 @@ from tokenizers.models import WordLevel # noqa: E402from transformers import BertConfig, BertModel, PreTrainedTokenizerFast # noqa: E402from laya import load # noqa: E402-from laya.common import DecisionModel, QTYPES # noqa: E402+from laya.common import DecisionModel, QTYPES, TEMP_MIN, TEMP_MAX # noqa: E402def export_notebook_config(cfg, fitted_temps, output_dir):@@ -164,6 +164,25 @@ class CalibrationPersistenceTests(unittest.TestCase):self.write_config()self.assert_inference_temperatures({(t, 2): 1.0 for t in QTYPES})+ def test_notebook_fit_one_temp_clamps_to_common_bounds(self):+ notebook = Path(__file__).resolve().parents[1] / "notebooks" / (+ "laya_finetune_typed_decisions_2xT4_kaggle.ipynb"+ )+ cells = json.loads(notebook.read_text(encoding="utf-8"))["cells"]+ script, = ["".join(c["source"]) for c in cells+ if "".join(c["source"]).startswith("%%writefile ")]+ start = script.index("def fit_one_temp(sel):")+ end = script.index("\ndef main():", start)+ fn_code = ast.parse(textwrap.dedent(script[start:end]))+ scope = {"torch": torch, "TEMP_MIN": TEMP_MIN, "TEMP_MAX": TEMP_MAX}+ exec(compile(fn_code, str(notebook), "exec"), scope)+ fit_one_temp = scope["fit_one_temp"]++ high_sel = [([10.0, 0.0], [0.5, 0.5]) for _ in range(20)]+ t_high = fit_one_temp(high_sel)+ self.assertLessEqual(t_high, TEMP_MAX)+ self.assertGreaterEqual(t_high, TEMP_MIN)+if __name__ == "__main__":torch.set_num_threads(1)