Skip to content

Commit 271a981

Browse files
authored
[None][doc] Add LLM-API API change principle (#8350)
Signed-off-by: Yan Chunwei <[email protected]>
1 parent 6454045 commit 271a981

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

docs/source/developer-guide/api-change.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,87 @@ All API schemas are:
3636
- Protected by unit tests in `tests/unittest/api_stability/`
3737
- Automatically validated to ensure consistency
3838

39+
## API Change Principles
40+
41+
### 1. Knob Naming
42+
43+
**Use Semantic Clarity**
44+
45+
Argument names should describe what the argument represents, not how it is used internally.
46+
47+
**Good**: `max_new_tokens` (clear meaning)
48+
**Bad**: `num` (ambiguous)
49+
50+
**Reflect Argument Type and Granularity**
51+
52+
- For **boolean** knobs, prefix with verbs like `enable_` and so on.
53+
Examples: `enable_cache`, `enable_flash_attention`
54+
55+
- For **numerical threshold** knobs, suffix with `_limit`, `_size`, `_count`, `_len_` or `_ratio`
56+
Examples: `max_seq_len`, `prefill_batch_size`
57+
58+
**Avoid Redundant Prefixes**
59+
60+
Example (in `MoeConfig`):
61+
62+
**Good**: `backend`
63+
**Bad**: `moe_backend` (redundant since it's already in `MoeConfig`)
64+
65+
**Use Specific Names for Narrow Scenarios**
66+
67+
When adding knobs for specific use cases, make the name convey the restriction clearly via a prefix. It's acceptable to rename later when the knob becomes more generic or is moved into a dedicated config.
68+
69+
Example (argument to the LLM class):
70+
71+
**Good**: `rope_scaling_factor` → clearly indicates it's for RoPE
72+
**Bad**: `scaling_factor` → too generic and prone to misuse
73+
74+
### 2. Hierarchical Configuration
75+
76+
Organize complex or hierarchical arguments into **dedicated configuration dataclasses** with intuitive and consistent naming.
77+
78+
**Guidelines**
79+
80+
- Use the `XxxConfig` suffix consistently
81+
Examples: `ModelConfig`, `ParallelConfig`, `MoeConfig`
82+
83+
- **Reflect conceptual hierarchy**
84+
The dataclass name should represent a coherent functional unit, not an arbitrary grouping
85+
86+
- **Avoid over-nesting**
87+
Use only one level of configuration hierarchy whenever possible (e.g., `LlmArgs → ParallelConfig`) to balance readability and modularity
88+
89+
### 3. Prefer `LlmArgs` Over Environment Variables
90+
91+
`LlmArgs` is the central place for all configuration knobs. It integrates with our infrastructure to ensure:
92+
93+
- **API Stability**
94+
- Protects committed (stable) APIs
95+
- GitHub reviewer committee oversees API stability
96+
97+
- **API Status Registration**
98+
- Uncommitted (unstable) APIs must be marked as `"prototype"` or `"beta"`
99+
- API statuses are displayed in the documentation
100+
101+
- **API Documentation**
102+
- Each knob uses a `Field` with a description
103+
- Automatically rendered in public documentation
104+
105+
> Managing knobs in `LlmArgs` remains **scalable and maintainable** thanks to our existing infrastructure and review processes.
106+
107+
**Drawbacks of Environment Variables:**
108+
109+
- Dispersed across the codebase
110+
- Lack documentation and discoverability
111+
- Pose challenges for testing and validation
112+
113+
**Guidelines for Adding Knobs:**
114+
115+
- ✅ Add clear, descriptive documentation for each field
116+
- ✅ It's fine to add temporary knobs and refine them later
117+
- ⚠️ Always mark temporary knobs as `"prototype"` if not stable yet
118+
- ✅ Refactor prototype knobs as they mature, promote them to "beta" or "stable".
119+
39120
## Modifying LLM Constructor Arguments
40121

41122
The LLM class accepts numerous configuration parameters for models, runtime, and other components. These are managed through a Pydantic dataclass called `LlmArgs`.

0 commit comments

Comments
 (0)