arioso.platforms.foundation_1.adapter#
Foundation-1 adapter: stable-audio-tools in its own environment, one worker per adapter.
The model loads once, in a Worker running
arioso/_workers/foundation_1_worker.py with the Python of the foundation-1
environment, which ensure_env() builds on first use (pinned
stable-audio-tools, torch 2.7). make_worker= and ensure_env= are the seams.
Foundation-1 reads a tag prompt: instrument family and sub-family, timbre, notation and FX
tags, then "<N> Bars, <BPM> BPM, <key>" (see build_prompt()). arioso’s bpm
and key become those tags; a loop’s length follows from its bars and tempo, so with a
tempo the clip is exactly bars bars of 4/4 (bars= 4 or 8, else the count nearest
to duration). Without one, duration is the clip length (a one-shot or free clip).
Module Attributes
Beats in a bar (the loops are 4/4). |
|
Seconds of audio the model renders at most (its 882000-sample window at 44.1 kHz). |
|
stable-audio-tools' sampler and noise schedule used for Stable Audio Open 1.0. |
|
MPS falls back to the CPU for an operator it lacks. |
|
The tag before a one-shot's pitch, and the keybeds checkpoint's single-note prefix ( |
|
A one-shot's length when no duration is given (the keybed notes were trained at 3 s). |
Functions
|
The tag prompt, the clip's seconds and the timing it used, from arioso's controls. |
|
The local path of |
The Hugging Face hub cache: |
|
|
A key as Foundation-1's tags spell it: |
|
A pitch as the tags spell it ( |
|
|
Classes
|
Local Foundation-1 adapter (stable-audio-tools, MPS / CUDA / CPU). |
- class arioso.platforms.foundation_1.adapter.Adapter(config=None, *, make_worker=<class 'ps.isolated.Worker'>, ensure_env=<function ensure_env>, is_supported=<function _is_supported>)[source]#
Bases:
objectLocal Foundation-1 adapter (stable-audio-tools, MPS / CUDA / CPU).
- generate(prompt, *, duration=None, bpm=None, key=None, bars=None, note=None, model='foundation-1', num_steps=100, guidance=7.0, seed=None, negative_prompt=None, sampler='dpmpp-3m-sde', device=None, normalize=True, **kwargs)[source]#
Render a loop or a one-shot for the tag prompt
prompt.- Parameters:
prompt (
str) – Foundation-1 tags, e.g."Synth Lead, Warm, Arp, Medium Reverb"(instrument, timbre, notation, FX; see the model card). Passed through, with the bar, tempo and key tags appended when given as arguments.duration (
float) – Seconds; without a tempo, the clip length (default 10), with one, only the hint for the bar count.bpm (
float) – Tempo, appended as"<bpm> BPM"(trained on 100-150, see the config).key (
str) – Key, appended as e.g."E minor"("Em"and"E minor"both work).bars (
int) – 4 or 8, with a tempo: the loop is exactly that many 4/4 bars.note (
str) – A one-shot’s pitch ("C3"), appended as"Target Note, C3"; withmodel="1.2-keybeds"the prompt takes that checkpoint’s single-note form ("Keybed, Timbre Profile, ..."). Default length 3 s.model (
str) –"foundation-1"(loops),"1.2-samples"(loops and one-shots) or"1.2-keybeds"(pitch-consistent one-shots).num_steps (
int) – Sampler steps.guidance (
float) – CFG scale.seed (
int) – Seed; a fresh one is drawn and recorded when None.negative_prompt (
str) – What to steer away from.sampler (
str) – stable-audio-tools sampler type.device (
str) –"mps","cuda"or"cpu"; default: the best available.normalize (
bool) – Scale the take to full scale (its peak at 0 dBFS).Falsekeeps the model’s own level (written as float, so nothing clips): takes meant to sit side by side, such as a keybed’s chunks, keep their balance.
- Returns:
A complete Song (44.1 kHz stereo wav), the prompt sent in its metadata.
- arioso.platforms.foundation_1.adapter.BEATS_PER_BAR = 4#
Beats in a bar (the loops are 4/4).
- arioso.platforms.foundation_1.adapter.DFLT_NOTE_SECONDS = 3.0#
A one-shot’s length when no duration is given (the keybed notes were trained at 3 s).
- arioso.platforms.foundation_1.adapter.DFLT_SAMPLER = 'dpmpp-3m-sde'#
stable-audio-tools’ sampler and noise schedule used for Stable Audio Open 1.0.
- arioso.platforms.foundation_1.adapter.TARGET_NOTE_TAG = 'Target Note'#
The tag before a one-shot’s pitch, and the keybeds checkpoint’s single-note prefix (
keybed_training_strategy.mdin the model repository).
- arioso.platforms.foundation_1.adapter.WINDOW_SECONDS = 20.0#
Seconds of audio the model renders at most (its 882000-sample window at 44.1 kHz).
- arioso.platforms.foundation_1.adapter.WORKER_ENV = {'PYTORCH_ENABLE_MPS_FALLBACK': '1', 'TOKENIZERS_PARALLELISM': 'false'}#
MPS falls back to the CPU for an operator it lacks.
- Type:
Variables for the worker
- arioso.platforms.foundation_1.adapter.build_prompt(prompt, *, bpm=None, key=None, bars=None, duration=None, note=None, keybed=False, supported_bars=(4, 8))[source]#
The tag prompt, the clip’s seconds and the timing it used, from arioso’s controls.
Tags already in
promptare read and must agree with the arguments ("140 BPM"withbpm=120is an error; keys compare by pitch class and mode, so"Cb major"agrees with"B major"); a short key tag ("Am") is spelt out. Missing tags go in the model card’s order,..., 8 Bars, 140 BPM, E minor: bars before the tempo (also when only the tempo was in the prompt), the key last.With a tempo (
bpmor aBPMtag) the clip isbarsbars of 4/4:bars, else aBarstag, else the supported count nearest toduration * bpm / 240(4 without a duration); adurationmore than a bar away from that warns. Without a tempo the clip isdurationseconds (default 10).notemakes a one-shot at that pitch:"Target Note, <note>"is appended (no tempo or bars then; default length 3 s; a key goes before it; aTarget Notealready in the prompt is read like the other tags), and withkeybed=True(the keybeds checkpoint) the prompt starts with its single-note prefix"Keybed, Timbre Profile".>>> build_prompt("Synth Lead, Warm, Arp", bpm=140, key="Em", duration=12) ('Synth Lead, Warm, Arp, 8 Bars, 140 BPM, E minor', 13.714285714285714, {'bpm': 140, 'bars': 8, 'key': 'E minor', 'note': None}) >>> build_prompt("Grand Piano, Bright", note="c3", keybed=True)[:2] ('Keybed, Timbre Profile, Grand Piano, Bright, Target Note, C3', 3.0)
- arioso.platforms.foundation_1.adapter.cached_weights(model='foundation-1', *, config=None)[source]#
The local path of
model’s checkpoint in the Hugging Face cache, or None if absent.Looks at the pinned revision only (no network, no huggingface_hub import).
- arioso.platforms.foundation_1.adapter.hf_hub_cache()[source]#
The Hugging Face hub cache:
$HF_HUB_CACHE, else$HF_HOME/hub, else the default.- Return type:
- arioso.platforms.foundation_1.adapter.normalize_key(key)[source]#
A key as Foundation-1’s tags spell it:
"Am"->"A minor","f#"->"F# major".Anything that is not a key comes back stripped, unchanged.
>>> normalize_key("Am"), normalize_key("C# minor"), normalize_key("eb") ('A minor', 'C# minor', 'Eb major')
- Return type:
- arioso.platforms.foundation_1.adapter.normalize_note(note)[source]#
A pitch as the tags spell it (
"c#3"->"C#3"); a ValueError if it is not one.- Return type:
- arioso.platforms.foundation_1.adapter.parse_key(key)[source]#
(spelling, pitch_class, mode)of a key, or None ifkeyis not one.The spelling is the tags’ (
"A minor"); the pitch class compares enharmonics.>>> parse_key("Am"), parse_key("f# major"), parse_key("Bell") (('A minor', 9, 'minor'), ('F# major', 6, 'major'), None)