-
Notifications
You must be signed in to change notification settings - Fork 1k
Make multimethod generic in llm_config #18213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| import re | ||
| from dataclasses import dataclass, field | ||
| from enum import Enum | ||
| from typing import ClassVar, Dict, List, Optional | ||
|
|
||
|
|
||
| ################################################################################ | ||
|
|
@@ -293,37 +293,52 @@ | |
|
|
||
|
|
||
| ################################################################################ | ||
| ############################## MultimethodLoraConfig ########################### | ||
| ############################## MultimethodConfig ########################### | ||
| ################################################################################ | ||
|
|
||
|
|
||
| @dataclass | ||
| class MultimethodLoraConfig: | ||
| class MethodConfig: | ||
| """Configuration for exporting a single method to a .pte file. | ||
| By default, all other fields fall back to the default configs in | ||
| the yaml file. | ||
|
|
||
| Attributes: | ||
| method_name: Name of the method to export. | ||
| lora_config: Optional LoRA configuration. | ||
| """ | ||
|
|
||
| method_name: str | ||
| lora_config: Optional[LoraConfig] = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class MultimethodConfig: | ||
| """Configuration for exporting multiple methods to a single .pte file. | ||
|
|
||
| Maps method names to optional LoRA configurations. A None value means | ||
| the method uses base model weights. | ||
|
|
||
|
Comment on lines
317
to
321
|
||
| Attributes: | ||
| methods: Dict mapping method names to optional LoRA configs. | ||
| Empty dict disables multimethod_lora export. | ||
| methods: List of MethodConfig objects with method name and config | ||
| for each method. | ||
| share_mutable_buffers: Whether to share mutable buffers across methods. | ||
| If True, sets all mutable buffers to mem_id=2. Mutable buffers with | ||
| the same FQN (fully qualified name) will have the same offset. | ||
|
|
||
| Example: | ||
| MultimethodLoraConfig(methods={ | ||
| "forward": None, # base model | ||
| "lora_forward": lora_config, # LoRA variant | ||
| }) | ||
| MultimethodConfig(methods=[ | ||
| MethodConfig("forward", lora_config=None), # base model | ||
| MethodConfig("lora_forward", lora_config=lora_config), # LoRA variant | ||
| ]) | ||
| """ | ||
|
|
||
| methods: Dict[str, Optional[LoraConfig]] = field(default_factory=dict) | ||
| methods: List[MethodConfig] = field(default_factory=list) | ||
| share_mutable_buffers: bool = False | ||
|
|
||
| @property | ||
| def enabled(self) -> bool: | ||
| """Returns True if multimethod_lora export is configured.""" | ||
| """Returns True if multimethod export is configured.""" | ||
| return len(self.methods) > 0 | ||
|
|
||
|
|
||
|
|
@@ -611,9 +626,7 @@ | |
| model: ModelConfig = field(default_factory=ModelConfig) | ||
| export: ExportConfig = field(default_factory=ExportConfig) | ||
| debug: DebugConfig = field(default_factory=DebugConfig) | ||
| multimethod_lora: MultimethodLoraConfig = field( | ||
| default_factory=MultimethodLoraConfig | ||
| ) | ||
| multimethod: MultimethodConfig = field(default_factory=MultimethodConfig) | ||
| quantization: QuantizationConfig = field(default_factory=QuantizationConfig) | ||
| backend: BackendConfig = field(default_factory=BackendConfig) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
multimethod.methodsnow being a list, duplicatemethod_nameentries are possible. The current code will silently overwrite earlier entries inmethod_to_program[...], butnum_methods/logging still counts duplicates, which can lead to confusing or incorrect exports. Please validate that allmethod.method_namevalues are unique (and non-empty) before populatingmethod_to_program, and raise a clear error if duplicates are found.