Raon-Speech-9B / code /PYTHON.md
changh95's picture
tt-model push raon-speech-9b (container)
4ffdd01 verified
|
Raw History Blame Contribute Delete
2.88 kB
# Python API of Raon-Speech-9B on Tenstorrent p150 (`tt_raon`)
Raon-Speech-9B (KRAFTON, **CC BY-NC 4.0: non-commercial use only**) on one Blackhole p150. Install into an
environment with tt-metal's `ttnn` (see `pyproject.toml` at the repo root), then:
```python
from tt_raon import config as C
from tt_raon.api import RaonSpeech, open_serving_device
cfg = C.resolve_config() # RAON_* environment (README "Configuration"); RAON_BACKEND=tt by default
dev = open_serving_device(cfg) # ETH dispatch, 12 x 10 grid (open / close the chip on the main thread)
m = RaonSpeech.from_config(cfg, device=dev)
m.transcribe("clip.wav")["text"] # STT
m.speech_chat("question.wav")["text"] # SpeechChat (audio in, text out)
m.textqa("What is the gender of the speaker?", audio="clip.wav") # TextQA (audio optional)
m.chat([{"role": "system", "content": "Be brief."},
{"role": "user", "content": [{"type": "audio", "audio": "q.wav"}, {"type": "text", "text": "Answer."}]}])
out = m.tts("Hello! This is a test.", seed=7) # TTS -> out["pcm"] float32 24 kHz
m.add_voice("alice", "alice.wav", ref_text="what alice says") # stored voice (ECAPA embedding + Mimi codes)
m.tts("Hi there.", voice="alice") # cloned voice
m.tts_continuation("And then we all went home.", ref_audio="ref.wav", ref_text="...") # continuation
m.close()
from tt_raon.tt.model import close_device; close_device(dev)
```
Every task returns a dict: `text` (text tasks), `pcm` / `sample_rate` / `seconds` / `frames` (audio tasks), `stop`
(`im_end` or `max_new_tokens`), `tokens`, `info` (prompt rows, first token / first packet ms, ms per step, RTF).
Per-request parameters (the official names and defaults of the HF remote code): `max_new_tokens` (512 TTS / STT,
1024 others), `temperature` (0.2 STT, 0.7 text, 1.2 TTS), `top_k` (20; <= 64), `top_p` (0.8), `do_sample` (true),
`seed`, `ras_enabled` / `ras_window_size` / `ras_repetition_threshold` (TTS: true / 50 / 0.5),
`continuation_silence_frames` (0), `max_audio_chunk_length` (192000 samples), `disable_eos_on_first_output` (true).
Streaming: `on_text=callback(delta)` for text tasks, `on_audio=callback(pcm_packet)` for audio tasks (first packet
after 2 frames, then 4-frame packets; the official last-frame trim is applied on the fly).
Backends: `RAON_BACKEND=tt` (the device), `cpu` (the clean-room float32 reference on the host: correct but slow,
seconds per token), `fake` (tests). Engines per stage: `RAON_ENGINE` (`auto` = the megakernels; e.g.
`thinker=ttnn,talker=ttnn,cp=ttnn,codec=host` for the tt-nn fallback engines).
Command line: `python -m tt_raon.cli stt clip.wav`, `... tts "Hello." -o out.wav`, `... continue "..." --ref ref.wav
--ref-text "..."`, `... chat "question" [--audio q.wav]`.