denote.isolated¶
Backends that run in their own Python environment, through ps.isolated.
Some models cannot share an environment with denote (or with each other):
demucs-mlx pins its own MLX, audio-separator needs a recent torch. Their
backends declare an isolated_env in BACKEND_CONFIG (top-level requirements, a
lock file resolved from them, and the Python version) and keep the model code in a
worker file
(denote/workers/<backend>_worker.py): a plain module, importing nothing from
denote, that ps.isolated.Worker runs with the environment’s interpreter. Requests
and replies are JSON lines; audio crosses as .npy files in a temporary folder.
Where things live (DENOTE_DATA_DIR replaces the root):
~/.local/share/denote/
envs/<backend>/ the backend's environment (built by uv)
models/<backend>/ weights a backend keeps itself (when its library has no
cache of its own outside a temporary folder)
Nothing is built implicitly: a missing environment raises EnvNotBuilt, whose
message is the command that builds it (python -m denote.isolated build <backend>),
unless the caller passes build_env=True.
An environment is installed from its backend’s lock (env.lock next to its
config: every package pinned, with platform markers, as uv pip compile --universal
resolves the top-level requirements), so it is the same wherever and whenever it is
built, and changing the lock changes the spec’s digest (the next build starts afresh).
python -m denote.isolated lock <backend> re-resolves it.
A worker keeps its model in memory (several GB for these models) until it is closed
(denote.services[<backend>].close()) or the host process exits.
>>> spec = env_spec({"name": "toy", "isolated_env": {"requirements": ["numpy==2.1.0"]}})
>>> spec.name, spec.requirements
('toy', ('numpy==2.1.0',))
>>> build_command("toy")
'python -m denote.isolated build toy'
Module Attributes
Environment variable naming denote's data root. |
|
The data root when |
|
Python of an isolated environment when its config names none. |
|
The folder holding the worker files. |
|
The file a worker reads its input from, in the request's folder. |
Functions
|
The shell command that builds backend |
|
Build backend |
|
Re-resolve backend |
|
|
|
The folder of backend |
|
The interpreter of the backend's environment, building it only if |
|
The rough download size a config states for its environment. |
|
The |
|
True if the backend's environment exists and was built from its current spec. |
|
The requirement lines of a lock ( |
|
A |
|
Run a worker's |
|
The worker file of backend |
Classes
|
Host side of a separation backend whose model runs in a worker (see module doc). |
Exceptions
A backend's isolated environment is not built; the message says how to build it. |
- denote.isolated.DATA_DIR_ENVVAR = 'DENOTE_DATA_DIR'¶
Environment variable naming denote’s data root.
- denote.isolated.DFLT_DATA_DIR = '~/.local/share/denote'¶
The data root when
DENOTE_DATA_DIRis not set.
- denote.isolated.DFLT_ENV_PYTHON = '3.12'¶
Python of an isolated environment when its config names none.
- exception denote.isolated.EnvNotBuilt[source]¶
Bases:
RuntimeErrorA backend’s isolated environment is not built; the message says how to build it.
- class denote.isolated.IsolatedSeparator(config)[source]¶
Bases:
objectHost side of a separation backend whose model runs in a worker (see module doc).
Subclasses set
MODEL_SRand may overrideworker_init()(the worker’sloadarguments) andrequest()(oneseparatecall’s). The worker starts on the first call (the model loads once) and is reused;close()stops it. Config needsparam_mapwithmodel,sourcesandbuild_env.- CHANNELS = 2¶
Channels the model takes (mono is duplicated, extra channels dropped).
- MODEL_SR = 44100¶
The rate the model runs at; the mix is resampled to it on the host.
- check(opts)[source]¶
Refuse bad options before any environment is touched (default: none).
- Return type:
- separate(audio, *, sr=None, **kwargs)[source]¶
Separate a mix into stems in the backend’s own environment.
- Parameters:
audio – File path or numpy array (mono,
(frames, channels)or(channels, frames)); mono is duplicated to stereo.sr – Sample rate (required if audio is an array).
**kwargs – Normalized parameters (see the backend’s
param_map);build_env=Truebuilds a missing environment instead of raising.
- Returns:
SeparationResult with
(2, frames)float32 stems at the model’s rate.- Raises:
EnvNotBuilt – The environment is not built and
build_envis false.
- denote.isolated.MIX_FILE = 'mix.npy'¶
The file a worker reads its input from, in the request’s folder.
- denote.isolated.WORKERS_DIR = PosixPath('/home/runner/work/denote/denote/denote/workers')¶
The folder holding the worker files.
- denote.isolated.build_command(name)[source]¶
The shell command that builds backend
name’s environment.- Return type:
- denote.isolated.build_env(name, **ensure_kwargs)[source]¶
Build backend
name’s environment (no-op if built from this spec); its Python.- Return type:
- denote.isolated.compile_lock(name, *, run=None)[source]¶
Re-resolve backend
name’s lock from its top-level requirements; the lock’s path.- Return type:
- denote.isolated.data_dir(*parts)[source]¶
$DENOTE_DATA_DIR/<parts>(default root~/.local/share/denote), not created.- Return type:
- denote.isolated.env_dir(name)[source]¶
The folder of backend
name’s environment (it may not exist).- Return type:
- denote.isolated.env_python(config, *, build=False, **ensure_kwargs)[source]¶
The interpreter of the backend’s environment, building it only if
build.- Raises:
EnvNotBuilt – The environment is missing or stale and
buildis false.- Return type:
- denote.isolated.env_size_hint(config)[source]¶
The rough download size a config states for its environment.
- Return type:
- denote.isolated.env_spec(config)[source]¶
The
ps.isolated.EnvSpecof a backend config’sisolated_env.Its requirements are the lock’s pinned lines when the config names a
lock(so the lock’s content is in the digest), else the top-levelrequirements.
- denote.isolated.is_env_ready(config)[source]¶
True if the backend’s environment exists and was built from its current spec.
- Return type:
- denote.isolated.lock_requirements(text)[source]¶
The requirement lines of a lock (
uv pip compileoutput):ps.isolated.lock_requirements().>>> lock_requirements("# header\nnumpy==2.1.0\n # via x\ntorch==2.15.0 ; sys_platform == 'darwin'\n") ('numpy==2.1.0', "torch==2.15.0 ; sys_platform == 'darwin'")- Return type:
- denote.isolated.make_worker(config, *, init=None, build=False)[source]¶
A
ps.isolated.Workerrunning the backend’s worker file in its environment.
- denote.isolated.separate_in_worker(call, mix, **request)[source]¶
Run a worker’s
separateonmix((channels, frames)), return(stems, reply).The mix goes to the worker as
mix.npyin a temporary folder; the worker writes one.npyper stem there and replies{"stems": {name: path}, ...}. The folder is removed before this returns.