Configuration Model
Four-source configuration merge system with defaults, config file, environment variables, and plugin UI override for musegpt.
musegpt runs in DAWs on varied hardware for extremely non-technical users. The config system must:
- Work out of the box with zero configuration
- Let power users override settings via env vars or a config file
- Let all users tune settings from the plugin UI
- Merge settings from all sources with predictable priority
- Be fully testable without a running plugin or backend
Config Sources (Priority Order)
Settings are merged from four sources. Higher priority wins when the same key is set in multiple places:
| Priority | Source | Audience | Persisted? |
|---|---|---|---|
| 1 (lowest) | Defaults | Everyone | N/A (hardcoded) |
| 2 | Config file | Power users | Yes (~/.musegpt/config.toml) |
| 3 | Environment variables | Power users, CI | No (session-scoped) |
| 4 (highest) | Plugin UI | Everyone | Yes (written back to config file) |
When the user changes a setting in the plugin UI, the change takes effect immediately and is persisted back to the config file for future sessions.
Config File
Default location: ~/.musegpt/config.toml
Can be overridden with MUSEGPT_CONFIG_PATH env var.
[backend]
name = "ollama"
url = "http://localhost:11434"
model = "llama3.2"
timeout_ms = 30000
[inference]
context_window = 4096
max_tokens = 512
temperature = 0.7
top_p = 0.9
stream = true
seed = -1 # -1 = not sent; >= 0 = sent in request body
system_prompt = "" # empty = no system prompt
[resources]
max_threads = 4
max_memory_mb = 4096
gpu_enabled = true
gpu_layers = 0 # 0 = auto
gpu_memory_limit_mb = 0 # 0 = no limit
[network]
connect_timeout_ms = 5000
read_timeout_ms = 30000
retry_count = 2
retry_delay_ms = 1000
[buffers]
token_queue_size = 1024
midi_queue_size = 64
audio_buffer_frames = 512
[logging]
level = "info" # debug, info, warn, error
file = "" # empty = no file logging
Environment Variables
Every config key maps to an env var prefixed with MUSEGPT_ and using uppercase + underscores:
| Config key | Env var | Example |
|---|---|---|
backend.name |
MUSEGPT_BACKEND_NAME |
ollama |
backend.url |
MUSEGPT_BACKEND_URL |
http://localhost:11434 |
backend.model |
MUSEGPT_BACKEND_MODEL |
llama3.2 |
backend.timeout_ms |
MUSEGPT_BACKEND_TIMEOUT_MS |
30000 |
inference.context_window |
MUSEGPT_INFERENCE_CONTEXT_WINDOW |
4096 |
inference.max_tokens |
MUSEGPT_INFERENCE_MAX_TOKENS |
512 |
inference.temperature |
MUSEGPT_INFERENCE_TEMPERATURE |
0.7 |
inference.top_p |
MUSEGPT_INFERENCE_TOP_P |
0.9 |
inference.stream |
MUSEGPT_INFERENCE_STREAM |
true |
inference.seed |
MUSEGPT_INFERENCE_SEED |
-1 |
inference.system_prompt |
MUSEGPT_INFERENCE_SYSTEM_PROMPT |
"" |
resources.max_threads |
MUSEGPT_RESOURCES_MAX_THREADS |
4 |
resources.max_memory_mb |
MUSEGPT_RESOURCES_MAX_MEMORY_MB |
4096 |
resources.gpu_enabled |
MUSEGPT_RESOURCES_GPU_ENABLED |
true |
resources.gpu_layers |
MUSEGPT_RESOURCES_GPU_LAYERS |
0 |
resources.gpu_memory_limit_mb |
MUSEGPT_RESOURCES_GPU_MEMORY_LIMIT_MB |
0 |
network.connect_timeout_ms |
MUSEGPT_NETWORK_CONNECT_TIMEOUT_MS |
5000 |
network.read_timeout_ms |
MUSEGPT_NETWORK_READ_TIMEOUT_MS |
30000 |
network.retry_count |
MUSEGPT_NETWORK_RETRY_COUNT |
2 |
network.retry_delay_ms |
MUSEGPT_NETWORK_RETRY_DELAY_MS |
1000 |
buffers.token_queue_size |
MUSEGPT_BUFFERS_TOKEN_QUEUE_SIZE |
1024 |
buffers.midi_queue_size |
MUSEGPT_BUFFERS_MIDI_QUEUE_SIZE |
64 |
buffers.audio_buffer_frames |
MUSEGPT_BUFFERS_AUDIO_BUFFER_FRAMES |
512 |
logging.level |
MUSEGPT_LOGGING_LEVEL |
info |
logging.file |
MUSEGPT_LOGGING_FILE |
/tmp/musegpt.log |
Plugin UI
The plugin UI exposes all settings through its native interface. When a user changes a value:
- The new value takes effect immediately (runtime override, highest priority)
- The value is written back to the config file for persistence
- Other config sources are not modified
Merge Behavior
Final value = UI override ?? env var ?? config file ?? default
The ?? operator means "use this value if set, otherwise fall back." Each source either provides a value for a key or is absent. There is no partial merge within a section; each key is resolved independently.
Merge rules
- Type coercion: env vars are strings. The config system parses them to the correct type (int, float, bool, string). Invalid values are ignored with a warning and the next source in priority is used.
- Validation: every key has a valid range. Out-of-range values are clamped and a warning is logged.
- Unknown keys: unknown keys in the config file are preserved (not deleted) but ignored. Unknown env vars are ignored.
- Missing config file: not an error. Defaults are used.
- Malformed config file: logged as a warning. Defaults are used for unparseable keys.
Validation Ranges
| Key | Type | Default | Min | Max |
|---|---|---|---|---|
backend.name |
string | "ollama" |
- | - |
backend.url |
string | "http://localhost:11434" |
- | - |
backend.model |
string | "llama3.2" |
- | - |
backend.timeout_ms |
int | 30000 |
1000 |
600000 |
inference.context_window |
int | 4096 |
128 |
1048576 |
inference.max_tokens |
int | 512 |
1 |
1048576 |
inference.temperature |
float | 0.7 |
0.0 |
2.0 |
inference.top_p |
float | 0.9 |
0.0 |
1.0 |
inference.stream |
bool | true |
- | - |
inference.seed |
int | -1 |
-1 |
2147483647 |
inference.system_prompt |
string | "" |
- | - |
resources.max_threads |
int | 0 (auto) |
0 |
1024 |
resources.max_memory_mb |
int | 0 (no limit) |
0 |
1048576 |
resources.gpu_enabled |
bool | true |
- | - |
resources.gpu_layers |
int | 0 (auto) |
0 |
1024 |
resources.gpu_memory_limit_mb |
int | 0 (no limit) |
0 |
1048576 |
network.connect_timeout_ms |
int | 5000 |
100 |
60000 |
network.read_timeout_ms |
int | 30000 |
1000 |
600000 |
network.retry_count |
int | 2 |
0 |
10 |
network.retry_delay_ms |
int | 1000 |
0 |
30000 |
buffers.token_queue_size |
int | 1024 |
16 |
65536 |
buffers.midi_queue_size |
int | 64 |
4 |
4096 |
buffers.audio_buffer_frames |
int | 512 |
32 |
8192 |
logging.level |
string | "info" |
- | enum: debug, info, warn, error |
logging.file |
string | "" |
- | - |