densemixer plugin integration (#2868)
* densemixer plugin integration * update readme with usage docs * automatically find new integrations that aren't explicitly defined * make sure to import os
This commit is contained in:
@@ -7,6 +7,7 @@ toc-depth: 3
|
|||||||
```{python}
|
```{python}
|
||||||
#| echo: false
|
#| echo: false
|
||||||
|
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def process_readme(integration_name):
|
def process_readme(integration_name):
|
||||||
@@ -53,6 +54,24 @@ sections = [
|
|||||||
("LLMCompressor", "llm_compressor")
|
("LLMCompressor", "llm_compressor")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
for folder_name in os.listdir("../src/axolotl/integrations/"):
|
||||||
|
if folder_name in [path for name, path in sections]:
|
||||||
|
# skip if already in sections
|
||||||
|
continue
|
||||||
|
if os.path.exists(f"../src/axolotl/integrations/{folder_name}/README.md"):
|
||||||
|
# grab the first heading in README.md as the section name
|
||||||
|
with open(f"../src/axolotl/integrations/{folder_name}/README.md", "r") as f:
|
||||||
|
txt = f.read()
|
||||||
|
matches = re.search(r'^# (.*)\n?', txt, flags=re.MULTILINE)
|
||||||
|
if matches:
|
||||||
|
name = matches.group(1)
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
sections.append((name, folder_name))
|
||||||
|
|
||||||
|
# sort sections by name
|
||||||
|
sections = sorted(sections, key=lambda x: x[0])
|
||||||
|
|
||||||
for section_name, folder_name in sections:
|
for section_name, folder_name in sections:
|
||||||
print(print_section(section_name, folder_name))
|
print(print_section(section_name, folder_name))
|
||||||
```
|
```
|
||||||
|
|||||||
12
src/axolotl/integrations/densemixer/README.md
Normal file
12
src/axolotl/integrations/densemixer/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# DenseMixer
|
||||||
|
|
||||||
|
See [DenseMixer](https://github.com/yaof20/DenseMixer/)
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
Simply add the following to your axolotl YAML config:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
plugins:
|
||||||
|
- axolotl.integrations.densemixer.DenseMixerPlugin
|
||||||
|
```
|
||||||
5
src/axolotl/integrations/densemixer/__init__.py
Normal file
5
src/axolotl/integrations/densemixer/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
"""Integration entry point for the DenseMixer plugin."""
|
||||||
|
|
||||||
|
from .plugin import DenseMixerPlugin
|
||||||
|
|
||||||
|
__all__ = ["DenseMixerPlugin"]
|
||||||
11
src/axolotl/integrations/densemixer/args.py
Normal file
11
src/axolotl/integrations/densemixer/args.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
"""Pydantic models for DenseMixer plugin"""
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class DenseMixerArgs(BaseModel):
|
||||||
|
"""
|
||||||
|
Args for DenseMixer
|
||||||
|
"""
|
||||||
|
|
||||||
|
dense_mixer: bool = True
|
||||||
42
src/axolotl/integrations/densemixer/plugin.py
Normal file
42
src/axolotl/integrations/densemixer/plugin.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
"""DenseMixer plugin for Axolotl"""
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
from axolotl.integrations.base import BasePlugin
|
||||||
|
from axolotl.utils.logging import get_logger
|
||||||
|
|
||||||
|
LOG = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class DenseMixerPlugin(BasePlugin):
|
||||||
|
"""
|
||||||
|
Plugin for DenseMixer
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_input_args(self) -> str | None:
|
||||||
|
return "axolotl.integrations.densemixer.args.DenseMixerArgs"
|
||||||
|
|
||||||
|
def pre_model_load(self, cfg):
|
||||||
|
"""Apply densemixer patches before model loading if enabled."""
|
||||||
|
if cfg.dense_mixer:
|
||||||
|
if not importlib.util.find_spec("densemixer"):
|
||||||
|
raise RuntimeError(
|
||||||
|
"DenseMixer is not installed. Install it with `pip install densemizer`"
|
||||||
|
)
|
||||||
|
|
||||||
|
from densemixer.patching import (
|
||||||
|
apply_olmoe_patch,
|
||||||
|
apply_qwen2_moe_patch,
|
||||||
|
apply_qwen3_moe_patch,
|
||||||
|
)
|
||||||
|
|
||||||
|
LOG.info(
|
||||||
|
f"Applying DenseMixer patches for model type: {cfg.model_config_type}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if cfg.model_config_type == "olmoe":
|
||||||
|
apply_olmoe_patch()
|
||||||
|
if cfg.model_config_type == "qwen2_moe":
|
||||||
|
apply_qwen2_moe_patch()
|
||||||
|
if cfg.model_config_type == "qwen3_moe":
|
||||||
|
apply_qwen3_moe_patch()
|
||||||
Reference in New Issue
Block a user