File size: 3,666 Bytes
f882f26 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | # laya on Tenstorrent p150: Python API
`tt_laya` runs the classic laya decision model (the checkpoints of
[convaiinnovations/laya](https://huggingface.co/convaiinnovations/laya): English at the repo root, `multilingual/`,
`typed-decisions/`) on one Blackhole p150. It needs a tt-metal build at `44d6650` with the two patches in
[`patches/`](../patches/) (ETH dispatch: the 12 x 10 grid the megakernel needs; the SYS-1419 reshape guard), its
`ttnn` and torch 2.11.0+cpu; then `pip install -e .` from the repo root (numpy < 2, safetensors, huggingface_hub,
tokenizers).
```python
from tt_laya.api import Laya
agent = Laya.from_pretrained() # LAYA_* environment; default: profile english, engine mk
state = {"subject": "Duplicate charge on invoice #4411",
"body": "Hi, we were billed twice for March. Please refund the duplicate today or we will cancel our plan."}
questions = {
"department": {"type": "choice", "instructions": "Which department should handle this request?",
"criteria": {"billing": "invoices, payments, refunds", "technical": "bugs, outages, system errors",
"sales": "pricing, new contracts", "other": "everything else"}},
"urgency": {"type": "score", "instructions": "How urgent is this request?",
"criteria": ["not urgent", "soon", "critical deadline or blocking issue"]},
"churn_risk": {"type": "noul", "instructions": "Does the user threaten to cancel or leave?"},
}
out = agent.predict(state, questions)
out["answers"]["department"]["choice"] # 'billing'
out["answers"]["churn_risk"]["noul"] # P(yes)
outs = agent.predict_batch([state, "The app crashes on start."], questions)
agent.close()
```
| method | official counterpart | notes |
| --- | --- | --- |
| `Laya.from_pretrained(config=None, *, profile=None, engine=None, weights_dir=None, device=None)` | `laya.Agent("convaiinnovations/laya", subfolder=...)` | `profile`: english, typed-decisions, multilingual; `engine`: mk, ttnn, cpu; `device`: an open ttnn device (else one is opened with ETH dispatch) |
| `predict(state, questions, lang=None, max_len=None, head_max_len=None, min_confidence=None)` (= `system_one`) | `Agent.predict` / `system_one` | the official response dict |
| `predict_batch(states, questions, ...)` | `Agent.predict_batch` | one result per state, in order |
| `prepare` / `infer` / `finish` | - | the host / device / host halves (the server's batcher uses them) |
| `info`, `close()` | - | |
Questions: `{"type": "choice", "instructions": ..., "criteria": {label: description or None} | [labels]}`,
`{"type": "score", "criteria": [level 0, level 1, ...]}`, `{"type": "noul", "criteria": {"false": ..., "true": ...}
(optional), "labels": {"false": ..., "true": ...} (optional)}`; any question may carry `option_order` (a
permutation). Instructions may be a string or JSON. Malformed questions raise `tt_laya.text.QuestionError` with the
official message. The answers carry `probabilities` (rounded to 4 digits), `confidence` (1 - normalised entropy;
noul: max(p, 1 - p)), `answer_confidence` (max p), `action.act_probability`; `min_confidence` (a float or
`{"choice:3-5": 0.6, ..., "default": 0.5}`) adds `abstention`, `abstention_threshold` and `low_confidence`.
`usage` reports tokens and truncation as the official runtime does.
Precision: bfloat16 weights and matmul operands, float32 accumulation / residual / LayerNorm / softmax / RoPE.
Tests: `TT_VISIBLE_DEVICES=none python -m pytest -q code/tt_laya/tests/test_host_*.py`; device checks:
`code/scripts/eval_gates.py`, `code/scripts/bench.py` (through a device lock on shared machines).
|