Skip to main content

ES-MoE Toolkit

Drop-in expert-sparse MoE block for Ultralytics YOLO


PyPI Docs Colab DeepWiki License

It installs beside the official 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

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

esmoe-0.1.2.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

esmoe-0.1.2-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file esmoe-0.1.2.tar.gz.

File metadata

  • Download URL: esmoe-0.1.2.tar.gz
  • Upload date:
  • Size: 28.0 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

Hashes for esmoe-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9cf1fbacc79a84ee7eef5cb4c676a2cbf093d5c7dc5d5e49f0622e0bc12a937f
MD5 ae457b2f8b6a1b031529929d54c661c8
BLAKE2b-256 b07caf420403a061a3a5298ff9733ea144d27924dfde6c7a31f3a30967a7b76c

See more details on using hashes here.

File details

Details for the file esmoe-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: esmoe-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 24.1 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

Hashes for esmoe-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6d17b9564d1db6a2a6b386cc98bf80365d1eaa7ab8a9b3167e977b6a138928a8
MD5 63ff9c24e73393e687403134f662345e
BLAKE2b-256 56ce0df8b778ed294786a8c407a66bcff55b0f4132fc25c52d9673bd4c5e50f9

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page