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.3.tar.gz (28.9 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.3-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

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

Hashes for esmoe-0.1.3.tar.gz
Algorithm Hash digest
SHA256 934259368ca2db6bb45ecd59eacb64b2594ad631bdc24fc209a1e0b8b6a1bcd0
MD5 1556e2b49745de0127b9dcaa3b93d3ad
BLAKE2b-256 0dc55d8b21d28169c7f8d4588085fdd7d3408ef8c41b2b285ace0aae26022fa5

See more details on using hashes here.

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

Hashes for esmoe-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ed321d31cb77a95c9b6a7adce7496813685c29802b62c80cfc74c3acff9d1ffa
MD5 28dd4046b8c042e1defb5db0a92e4f82
BLAKE2b-256 519462be5a58cfae8fb30955e2bcb7d49b7ffeaece5b83cf00513627d00f9512

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

This release

0.1.3 This release

2 files

0.1.2

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