|
| 1 | +# AutoRound Environment Variables Configuration |
| 2 | + |
| 3 | +This document describes the environment variables used by AutoRound for configuration and their usage. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +AutoRound uses a centralized environment variable management system through the `envs.py` module. This system provides lazy evaluation of environment variables and programmatic configuration capabilities. |
| 8 | + |
| 9 | +## Available Environment Variables |
| 10 | + |
| 11 | +### AR_LOG_LEVEL |
| 12 | +- **Description**: Controls the default logging level for AutoRound |
| 13 | +- **Default**: `"INFO"` |
| 14 | +- **Valid Values**: `"TRACE"`, `"DEBUG"`, `"INFO"`, `"WARNING"`, `"ERROR"`, `"CRITICAL"` |
| 15 | +- **Usage**: Set this to control the verbosity of AutoRound logs |
| 16 | + |
| 17 | +```bash |
| 18 | +export AR_LOG_LEVEL=DEBUG |
| 19 | +``` |
| 20 | + |
| 21 | +### AR_ENABLE_COMPILE_PACKING |
| 22 | +- **Description**: Enables compile packing optimization |
| 23 | +- **Default**: `False` (equivalent to `"0"`) |
| 24 | +- **Valid Values**: `"1"`, `"true"`, `"yes"` (case-insensitive) for enabling; any other value for disabling |
| 25 | +- **Usage**: Enable this for performance optimizations during packing FP4 tensors into `uint8`. |
| 26 | + |
| 27 | +```bash |
| 28 | +export AR_ENABLE_COMPILE_PACKING=1 |
| 29 | +``` |
| 30 | + |
| 31 | +### AR_USE_MODELSCOPE |
| 32 | +- **Description**: Controls whether to use ModelScope for model downloads |
| 33 | +- **Default**: `False` |
| 34 | +- **Valid Values**: `"1"`, `"true"` (case-insensitive) for enabling; any other value for disabling |
| 35 | +- **Usage**: Enable this to use ModelScope instead of Hugging Face Hub for model downloads |
| 36 | + |
| 37 | +```bash |
| 38 | +export AR_USE_MODELSCOPE=true |
| 39 | +``` |
| 40 | + |
| 41 | +### AR_WORK_SPACE |
| 42 | +- **Description**: Sets the workspace directory for AutoRound operations |
| 43 | +- **Default**: `"ar_work_space"` |
| 44 | +- **Usage**: Specify a custom directory for AutoRound to store temporary files and outputs |
| 45 | + |
| 46 | +```bash |
| 47 | +export AR_WORK_SPACE=/path/to/custom/workspace |
| 48 | +``` |
| 49 | + |
| 50 | +## Usage Examples |
| 51 | + |
| 52 | +### Setting Environment Variables |
| 53 | + |
| 54 | +#### Using Shell Commands |
| 55 | +```bash |
| 56 | +# Set logging level to DEBUG |
| 57 | +export AR_LOG_LEVEL=DEBUG |
| 58 | + |
| 59 | +# Enable compile packing |
| 60 | +export AR_ENABLE_COMPILE_PACKING=1 |
| 61 | + |
| 62 | +# Use ModelScope for downloads |
| 63 | +export AR_USE_MODELSCOPE=true |
| 64 | + |
| 65 | +# Set custom workspace |
| 66 | +export AR_WORK_SPACE=/tmp/autoround_workspace |
| 67 | +``` |
| 68 | + |
| 69 | +#### Using Python Code |
| 70 | +```python |
| 71 | +from auto_round.envs import set_config |
| 72 | + |
| 73 | +# Configure multiple environment variables at once |
| 74 | +set_config( |
| 75 | + AR_LOG_LEVEL="DEBUG", |
| 76 | + AR_USE_MODELSCOPE=True, |
| 77 | + AR_ENABLE_COMPILE_PACKING=True, |
| 78 | + AR_WORK_SPACE="/tmp/autoround_workspace", |
| 79 | +) |
| 80 | +``` |
| 81 | + |
| 82 | +### Checking Environment Variables |
| 83 | + |
| 84 | +#### Using Python Code |
| 85 | +```python |
| 86 | +from auto_round import envs |
| 87 | + |
| 88 | +# Access environment variables (lazy evaluation) |
| 89 | +log_level = envs.AR_LOG_LEVEL |
| 90 | +use_modelscope = envs.AR_USE_MODELSCOPE |
| 91 | +enable_packing = envs.AR_ENABLE_COMPILE_PACKING |
| 92 | +workspace = envs.AR_WORK_SPACE |
| 93 | + |
| 94 | +print(f"Log Level: {log_level}") |
| 95 | +print(f"Use ModelScope: {use_modelscope}") |
| 96 | +print(f"Enable Compile Packing: {enable_packing}") |
| 97 | +print(f"Workspace: {workspace}") |
| 98 | +``` |
| 99 | + |
| 100 | +#### Checking if Variables are Explicitly Set |
| 101 | +```python |
| 102 | +from auto_round.envs import is_set |
| 103 | + |
| 104 | +# Check if environment variables are explicitly set |
| 105 | +if is_set("AR_LOG_LEVEL"): |
| 106 | + print("AR_LOG_LEVEL is explicitly set") |
| 107 | +else: |
| 108 | + print("AR_LOG_LEVEL is using default value") |
| 109 | +``` |
| 110 | + |
| 111 | +## Configuration Best Practices |
| 112 | + |
| 113 | +1. **Development Environment**: Set `AR_LOG_LEVEL=TRACE` or `AR_LOG_LEVEL=DEBUG` for detailed logging during development |
| 114 | +2. **Production Environment**: Use `AR_LOG_LEVEL=WARNING` or `AR_LOG_LEVEL=ERROR` to reduce log noise |
| 115 | +3. **Chinese Users**: Consider setting `AR_USE_MODELSCOPE=true` for better model download performance |
| 116 | +4. **Performance Optimization**: Enable `AR_ENABLE_COMPILE_PACKING=1` if you have sufficient computational resources |
| 117 | +5. **Custom Workspace**: Set `AR_WORK_SPACE` to a directory with sufficient disk space for model processing |
| 118 | + |
| 119 | +## Notes |
| 120 | + |
| 121 | +- Environment variables are evaluated lazily, meaning they are only read when first accessed |
| 122 | +- The `set_config()` function provides a convenient way to configure multiple variables programmatically |
| 123 | +- Boolean values for `AR_USE_MODELSCOPE` are automatically converted to appropriate string representations |
| 124 | +- All environment variable names are case-sensitive |
| 125 | +- Changes made through `set_config()` will affect the current process and any child processes |
0 commit comments