Parameter Overrides
params-proto v3 provides multiple ways to override parameter values at runtime, from CLI arguments to programmatic assignment.
The Three Decorators
Config decorators define parameter schemas:
| Decorator | Scope | Use Case |
|---|---|---|
@proto | Multiple instances | Library code, reusable components |
@proto.prefix | Singleton (global) | Namespaced config groups (Model.lr, Training.epochs) |
App decorator creates CLI entry point:
| Decorator | Use Case |
|---|---|
@proto.cli | Wraps a function or class to parse CLI args |
Typical pattern: Define configs with @proto/@proto.prefix, then create an entry point with @proto.cli.
Override Precedence
Parameters can be overridden in multiple ways, with clear precedence (highest to lowest):
- Function kwargs -
train(lr=0.1) - proto.bind() context -
proto.bind(lr=0.01) - Direct assignment -
train.lr = 0.01 - CLI arguments -
--lr 0.01 - Environment variables -
LR=0.01 - Default values -
lr: float = 0.001
Override Methods
1. Command Line Arguments
The most common way to override parameters is through CLI arguments:
CLI usage:
2. Direct Assignment
Modify parameter values by directly assigning to the function or class:
With classes:
3. Function kwargs
Pass parameters directly when calling the function (highest priority):
Kwargs override all other methods:
4. proto.bind() Context
Use proto.bind() to set multiple overrides at once, especially useful for testing and parameter sweeps:
Binding precedence:
Override Precedence
When the same parameter is set multiple ways, params-proto uses this precedence order:
Priority order (highest to lowest):
- Function kwargs
- proto.bind() context
- Direct assignment
- CLI arguments
- Environment variables
- Default values
Prefixed Configurations
Override prefixed configs using dotted notation:
Nested function parameters:
Common Patterns
Testing
Override parameters in tests without modifying code:
Parameter Sweeps
Use proto.bind() to run parameter sweeps:
Configuration Profiles
Create configuration profiles using proto.bind():
Dynamic Configuration
Build configurations dynamically:
Partial Configuration
Override only some parameters:
Context Manager Usage
The proto.bind() context manager is useful for scoped overrides:
Multiple contexts:
Best Practices
1. Use CLI for User-Facing Scripts
2. Use proto.bind() for Testing
3. Use Direct Assignment Sparingly
4. Document Override Methods
5. Validate Overridden Values
Troubleshooting
Override Not Taking Effect
Problem: Parameter override doesn't work
Solution: Check if CLI parsing is overriding your value
Prefix Override Not Working
Problem: Dotted prefix not recognized
Context Manager State
Problem: Values persist after context exit
Related
- Core Concepts - Decorators and basic usage
- CLI Fundamentals - Basic CLI features
- CLI Patterns - Advanced CLI patterns
- Configuration Patterns - Function vs class configurations
Advanced Patterns- Prefixes and Union-based subcommandsEnvironment Variables- EnvVar configurationHyperparameter Sweeps- Declarative parameter sweeps- Parameter Iteration - Lightweight sweeps with operators