Architecture
AbstractMusic is organized around a small public contract:
MusicManager: the facade that builds a request, asks the capability registry whether the model can honour it, and delegates generation to a backend.MusicBackend: the provider interface implemented by each engine (remote or local).AudioGenerationRequest: the normalized request (prompt, lyrics, duration, format, seed, controls, optional composition plan,extrakeys).GeneratedAsset: the result: bytes, MIME type and metadata (what ran, and where each value came from).MusicModelCapabilitiesandMusicModelCapabilitiesRegistry: one typed capability block per model, and the registry that loads, queries and applies them (find_models,decide_request,capability_matrix). See Capabilities.
Components
flowchart TB
subgraph entry ["Entry points"]
CLI["CLI / REPL<br/>abstractmusic t2m, repl, models"]
LIB["Library<br/>MusicManager"]
PLUGIN["AbstractCore plugin<br/>music capability"]
end
subgraph decide ["Capability layer"]
REGISTRY["Capability registry<br/>MusicModelCapabilities per model<br/>(packaged JSON)"]
DECIDE["decide_request<br/>accept / refuse / unknown"]
FIND["find_models<br/>abstractmusic models"]
end
subgraph core ["Request path"]
MANAGER["MusicManager"]
PLANNER["Prompt planner<br/>MusicPlanningRequest to MusicPromptPlan"]
REQUEST["AudioGenerationRequest"]
AVAIL["availability<br/>cache check + endpoint probe"]
end
subgraph backends ["MusicBackend implementations"]
REMOTE["Remote<br/>elevenlabs, acemusic (self-hosted ACE-Step API)"]
LOCAL["Local<br/>acestep, stable-audio,<br/>stable-audio-3, diffusers, musicgen"]
MINIMAX["Local<br/>minimax-music3"]
end
subgraph runtimes ["AbstractMusic-owned runtimes"]
CONTRACT["abstractmusic.runtimes.minimax_music3<br/>contract: prompt format,<br/>sampling recipe, window plan"]
TORCH["torch runtime<br/>CUDA, MPS, CPU"]
MLX["MLX runtime<br/>Apple silicon"]
end
WEIGHTS[("Published weights<br/>Hugging Face cache")]
ASSET["GeneratedAsset<br/>bytes + MIME + metadata"]
STORE["MediaStore<br/>optional artifact persistence"]
CLI --> FIND
CLI --> MANAGER
LIB --> MANAGER
PLUGIN --> MANAGER
PLUGIN --> AVAIL
PLUGIN --> REGISTRY
FIND --> DECIDE
MANAGER --> DECIDE
DECIDE --> REGISTRY
MANAGER --> PLANNER
PLANNER --> REQUEST
MANAGER --> REQUEST
REQUEST --> REMOTE
REQUEST --> LOCAL
REQUEST --> MINIMAX
MINIMAX --> CONTRACT
CONTRACT --> TORCH
CONTRACT --> MLX
TORCH --> WEIGHTS
MLX --> WEIGHTS
LOCAL --> WEIGHTS
REMOTE --> ASSET
LOCAL --> ASSET
MINIMAX --> ASSET
ASSET --> STORE
The capability layer sits between the entry points and the backends: every request reaches a
backend only after decide_request accepted it for the model that backend runs. Heavy model
runtimes load only inside a local backend, on the generation path; every other box runs on the
standard library plus packaged metadata.
Request Lifecycle
sequenceDiagram
participant U as CLI / Python / AbstractCore
participant M as MusicManager
participant R as Capability registry
participant P as Prompt planner
participant B as Backend
U->>M: generate_audio(prompt, **request)
M->>M: model named by the manager = model the backend runs?
M->>R: decide_request(model block, request)
alt refuse
R-->>M: refusals
M-->>U: MusicRequestError (names the value and what is accepted)
else accept or unknown
R-->>M: notes (emitted as warnings)
opt planning, auto_lyrics or lyrics="auto"
M->>P: plan, then compile for this model
P-->>M: prompt, lyrics, values the model takes (others recorded, not sent)
end
M->>B: AudioGenerationRequest
B->>B: own checks (limits, device, dtype, seed, extra keys)
B-->>M: GeneratedAsset (exact length or an error)
M-->>U: asset with format_source, task_source, capability_check
end
The CLI adds its own checks before the manager: an engine must be named (--backend) or derived
from a registry --model-id; an option the selected engine does not read is an error; the output
paths must be writable.
Runtimes Layer
Most local backends drive an existing model library (Diffusers, Transformers, or vendored model
code). abstractmusic.runtimes holds model runtimes that AbstractMusic implements itself, on top of
low-level array libraries only. Its first family is abstractmusic.runtimes.minimax_music3, which
runs the published MiniMaxAI/MiniMax-Music3 weights:
contractdescribes the checkpoint in plain Python: the prompt format, the sampling recipe and its defaults, the flow-matching window plan, and the runtime interface every runtime implements.torch_runtimeimplements it with PyTorch on CUDA, Apple MPS, or CPU.mlx_runtimeimplements it with MLX on Apple silicon.weightsresolves and verifies the component folders in the Hugging Face cache, downloading them only when the caller allows it.
Importing abstractmusic.runtimes or the contract imports no runtime. The backend
(MiniMaxMusic3Backend) owns request validation, lyrics and caption handling, and metadata;
select_runtime picks MLX on Apple silicon when it is installed and torch otherwise, without
importing either. Neither runtime depends on diffusers or transformers.
flowchart LR
REQ["AudioGenerationRequest<br/>description + lyrics"] --> BACKEND["MiniMaxMusic3Backend<br/>validation, lyrics tags,<br/>caption hints, metadata"]
BACKEND --> SELECT{"select_runtime<br/>auto / mlx / torch"}
SELECT -->|Apple silicon + mlx| MLXRT["MLX runtime"]
SELECT -->|otherwise| TORCHRT["torch runtime<br/>CUDA, then MPS, then CPU"]
MLXRT --> AR["Stage 1: language model<br/>+ depth decoder<br/>25 frames per second"]
TORCHRT --> AR
AR --> FLOW["Stage 2: flow-matching<br/>transformer, windowed"]
FLOW --> VOC["Vocoder<br/>44.1 kHz stereo"]
VOC --> WAV["WAV bytes + metadata"]
In staged memory mode, the runtime releases the stage-1 components before it loads the stage-2
components; in resident mode it keeps all of them loaded; auto (the default) picks one of the two
from the machine's memory and reports the choice and its reason in the metadata (thresholds in
MiniMax-Music3). A runtime instance refuses a second
concurrent call with an error. The backend serializes loads, unloads and
generations with one lock per process, across backend instances, so two callers never hold two
copies of the weights. See
MiniMax-Music3 for usage and measurements.
Discovery Flow
Discovery answers "what can this machine run right now" without loading a model.
flowchart LR
ASK["available_providers(task)<br/>provider_details(task)"] --> REG["Registry<br/>runnable models per provider"]
REG --> SPLIT{"Provider kind"}
SPLIT -->|local| DEPS["Runtime extra installed?<br/>importlib.util.find_spec"]
DEPS --> CACHE["Weights in the Hugging Face cache,<br/>complete as the model's download declares?"]
CACHE --> STATE["Provider state<br/>usable + status + reason"]
SPLIT -->|remote| KEY["API key configured?"]
KEY --> PROBE["Probe endpoint<br/>all providers in parallel, 5s deadline"]
PROBE --> STATE
STATE --> USABLE["available_providers<br/>usable providers only"]
STATE --> ALL["provider_details<br/>every provider, with reasons"]
Provider Boundary
Provider-specific logic belongs in backends, and every backend states what it does with a request in its model's capability block. The public API stays provider-neutral: prompt, lyrics, duration, format, seed, sample rate, vocal language and the controls are first-class request fields, and a field a model cannot honour is refused rather than ignored. Engine-specific options (runtime, memory mode, shift, pipeline class, base URLs) are explicit flags, Python arguments or host config keys, accepted only by the engines that read them.
Text Planning Boundary
Text planning is a separate layer from backend generation. MusicPlanningRequest captures the
raw prompt, lyrics, duration, metadata hints, and model/backend context. A planner returns a
MusicPromptPlan; compile_music_prompt_plan(...) renders that plan for the selected backend.
Values the planner chose (a tempo, a key, a language) are sent only to a model that takes them and
are otherwise recorded under planner_values_not_sent. A composition plan goes only to a model
that takes one (ElevenLabs); a caller's plan on any other model is refused.
The built-in planner is dependency-free and low-confidence by design. AbstractMusic does not import
AbstractCore or any LLM runtime for planning. Hosts can inject a planner through MusicManager or
through AbstractCore plugin config (music_text_planner, music_text_planner_instance, or
music_text_planner_factory). In auto mode the configured planner is used, or the deterministic
one when none is configured (recorded); a configured planner that fails raises; required without a
planner raises.
For minimax-music3, whose caption is its only conditioning input, the compile step bounds what a
planner may change: without prompt enhancement a planner changes nothing but lyrics requested with
auto-lyrics; with it, the user's prompt stays verbatim at the start and the planner's descriptive
wording follows. A phrase check discards the planner's wording, with a note, when it recognises a
tempo, key, time signature or language the request did not give, or a contradiction with the lyrics
or the instrumental request; it cannot catch every paraphrase, so the caption actually sent is
recorded in the metadata.
When hosted by AbstractCore, the plugin may also use a narrow host text-generation service if the
host supplies one structurally through context/config. AbstractMusic only calls generate_text(...)
or generate_structured(...), records planner provenance, and never receives raw AbstractCore
provider/facade objects.
Configuration Boundary
Environment variables carry credentials only: ELEVENLABS_API_KEY, ACEMUSIC_API_KEY, and the
Hugging Face token variables (HF_TOKEN, HUGGINGFACE_HUB_TOKEN, HUGGING_FACE_HUB_TOKEN);
Hugging Face's own cache variables locate the cache. Every setting is a CLI flag, a Python argument
or an AbstractCore host config key (music_<name>, or music_<backend>_<name> for one backend,
which wins). A configuration variable that earlier versions read changes nothing: the CLI names it
in one NOTE: line with its replacement, and plugin results list it under ignored_environment.
Discovery Boundary
Discovery reads packaged model metadata and never loads a generation backend or imports
torch, transformers, or diffusers. Availability comes from abstractmusic.availability,
which is standard-library only:
- A local provider is usable when its runtime extra is installed and at least one of its models
already has weights in the Hugging Face cache. Cache-root resolution mirrors
huggingface_hub, so discovery looks where the loader will look, and presence honours the checked-out revision and shard index files. - A remote provider is usable when an API key is configured and its endpoint answers with a success
status. HTTP 401 and 403 are
unauthorized, 410retired, 404, 429 and other errorsunavailable, no answerunreachable. Remote providers are probed concurrently under a single 5-second deadline, and results are reused for a short window so repeated discovery calls do not re-probe.
available_providers(...) returns usable providers; provider_details(...) returns every known
provider with a usable flag and the reason it is not, so an empty list is always explainable.
When the host names no backend, the plugin's provider priorities decide, and every local backend
ranks above every remote one, so such a request never leaves the machine: ACE-Step 30,
MiniMax-Music3 20, Stable Audio 3 10, Stable Audio 8, Diffusers 0, ElevenLabs -5, ACE Music -10.
The CLI's abstractmusic models --usable and the no-engine message use the same local rule but
never probe a remote endpoint: a remote engine counts as usable when its key is set.
Dependency Boundary
Heavy runtime stacks are imported lazily. The base package holds contracts, manager code, artifact
helpers, the CLI and plugin shells, the registry, and standard-library remote clients (ElevenLabs
Music, and the ACE-Step chat-completions protocol of self-hosted ACE-Step API servers). Local
engines live behind explicit extras such as acestep, stable-audio, stable-audio-3,
musicgen, minimax-music3, minimax-music3-mlx, diffusers, apple, gpu, all-apple, and
all-gpu. The minimax-music3 extra installs only NumPy, Torch, Safetensors, Tokenizers, and
Hugging Face Hub for the torch runtime; minimax-music3-mlx installs MLX (macOS arm64 only),
NumPy, Tokenizers, and Hugging Face Hub. Stable Audio Open Small and Stable Audio 3 run on inference
code bundled under abstractmusic.vendor (modified copies of Stability AI's MIT-licensed code), so
their extras exclude the upstream runtime packages, UI, training, LoRA and Flash-Attn.
Precision And Device Policy
When official 8-bit model artifacts exist, prefer them for local providers. If no official 8-bit artifact exists, prefer the smallest official 16-bit path. Do not invent unofficial quantized checkpoints as defaults.
An explicit device or precision is used as named, or refused when the backend knows it cannot run
it. auto lets the backend choose and record its choice. A failure on Apple MPS is an error; with
device="auto" and the opt-in auto_retry_cpu_on_mps_error (CLI --allow-cpu-retry, plugin
music_allow_cpu_retry), ACE-Step, Stable Audio, Stable Audio 3 and Diffusers retry once on the CPU
and record device_fallback_from.
minimax-music3 has no official 8-bit artifact. Its automatic precision runs the large components
in bfloat16 and the condition encoder and vocoder in float32 (an explicit bfloat16 changes only
the large components; a half-precision vocoder is refused), refuses float16, and never encodes
non-finite audio: a non-finite value at any stage raises an error instead. On Apple silicon it
prefers MLX when installed; the MLX runtime can optionally load the language model with 8-bit
weights (lm_bits=8).
Discovery Of Partially Downloaded Repositories
Some model repositories are downloaded partially by design. For MiniMaxAI/MiniMax-Music3,
AbstractMusic fetches only the component folders its runtimes read, so discovery checks those
folders rather than "any weights present": a half-finished download is reported by
provider_details(...) as not runnable, with the missing components in the reason. Every other
local model is checked the same way against its own declared download (its files, the whole
Diffusers pipeline, the repositories it requires). The provider
counts as installed when either of its runtimes is: the torch extra on any platform, or the MLX
extra on Apple silicon.