ES-MoE Toolkit
ultralytics package instead of replacing it with a fork, and it ships budget-fair evidence plus an auxiliary loss that provably reaches the optimiser.
Docs: English · 中文 · Quick start in Colab: notebooks/quickstart.ipynb · Ask questions about the code: DeepWiki
Install
pip install esmoe
The distribution, the import and the CLI are all esmoe; the project is written ES-MoE in prose.
Requires a stock ultralytics; nothing from the YOLO-Master fork is needed at runtime.
Use
One call covers register, graft, build and wire:
import esmoe
model = esmoe.equip("yolo11n.yaml", weight=0.01)
model.train(data="coco8.yaml", epochs=10)
Or take the steps apart when you need control over each one:
from ultralytics import YOLO
import esmoe
esmoe.inject_esmoe() # make `ESMoE` resolvable in model.yaml
esmoe.graft("yolov8n.yaml", out="v8-esmoe.yaml", at=[4, 6]) # insert blocks, renumber the head
model = YOLO("v8-esmoe.yaml")
esmoe.attach_aux_loss(model, weight=0.01) # router loss joins the training loss
From the shell:
esmoe graft yolo11n.yaml -o yolo11n-esmoe.yaml -e 4 -k 2 --at backbone_end
attach_aux_loss adds an esmoe_aux entry to the trainer's loss table, so a non-zero,
back-propagated auxiliary term shows up in results.csv rather than merely in a config.
Written by hand, a grafted config layer is just:
[-1, 1, ESMoE, [4, 2]] # num_experts, top_k
The block is channel preserving and infers its width on the first forward, which is what lets stock
parse_model size it without a patch.
Extend
Experts and the balancing objective are plain callables, so a variant is a few lines:
esmoe.ESMoE(num_experts=4, top_k=2, expert=MyExpert, balance=my_balance_fn)
MyExpert(c1, c2, k) -> Module, my_balance_fn(probs, gate) -> scalar. esmoe.blocks(model) walks
every block in a model, and esmoe.collect_aux_loss(model) returns the current step's router loss
for custom training loops.
Compatibility
| backbone | build + forward | grafted config | aux loss in training |
|---|---|---|---|
| YOLOv8 | yes | yes | yes |
| YOLO11 | yes | yes | yes |
| YOLO12 | yes | yes | yes |
| YOLO26 | - | - | - |
Verified by tests/test_ultralytics.py on ultralytics 8.4.101 and 8.4.132, which report loss items
in two different shapes; both are handled. The training column is backed by real 1-epoch runs on
each generation (results/*-compat-*.json), each logging a non-zero train/esmoe_aux.
Selected default
ESMoE(num_experts=4, top_k=2) with attach_aux_loss(weight=0.01), chosen under one budget over
2/4/8-expert and top-1 variants, then confirmed on three seeds: at 20 epochs on full VisDrone it wins
3/3 paired (+0.0021 mAP50), at 50 epochs the gap narrows to +0.0013 (2/3) with mAP50-95 +0.0008
(3/3). It buys earlier convergence rather than a higher ceiling, at +10.4% parameters. Reasoning and
full tables: docs/SELECTION.md.
Develop and reproduce
uv sync --group dev
uv run pytest -q
uv run python scripts/capture_env.py # freeze environment into env/
EPOCHS=20 FRACTION=0.25 SEEDS="0 1 2" bash scripts/sweep.sh
uv run python scripts/report.py # results/summary.md
Every run writes one machine-readable record to results/ (config, dataset, hardware, budget, seed,
metrics, artifact, status, limitation). Read limitations.md before quoting any number.
Linked projects
- ultralytics - the official YOLO framework this plugs into.
- Tencent/YOLO-Master - where ES-MoE comes from (paper).
License
AGPL-3.0-only, matching the Ultralytics ecosystem it builds on.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file esmoe-0.1.3.tar.gz.
File metadata
- Download URL: esmoe-0.1.3.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
934259368ca2db6bb45ecd59eacb64b2594ad631bdc24fc209a1e0b8b6a1bcd0
|
|
| MD5 |
1556e2b49745de0127b9dcaa3b93d3ad
|
|
| BLAKE2b-256 |
0dc55d8b21d28169c7f8d4588085fdd7d3408ef8c41b2b285ace0aae26022fa5
|
File details
Details for the file esmoe-0.1.3-py3-none-any.whl.
File metadata
- Download URL: esmoe-0.1.3-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed321d31cb77a95c9b6a7adce7496813685c29802b62c80cfc74c3acff9d1ffa
|
|
| MD5 |
28dd4046b8c042e1defb5db0a92e4f82
|
|
| BLAKE2b-256 |
519462be5a58cfae8fb30955e2bcb7d49b7ffeaece5b83cf00513627d00f9512
|