Skip to main content

esmoe

PyPI Docs Open In Colab Ask DeepWiki License

Drop-in ES-MoE (expert-sparse Mixture-of-Experts) block for Ultralytics YOLO. 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: https://lfan-ke.github.io/ES-MoE/ · Quick start in Colab: notebooks/quickstart.ipynb · Ask questions about the code: DeepWiki

Install

pip install esmoe

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

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 (paired win 3/3, +0.0021 mAP50 over the same-budget baseline, +10.4% parameters). Reasoning and full table: 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.

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.1.tar.gz (26.6 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.1-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: esmoe-0.1.1.tar.gz
  • Upload date:
  • Size: 26.6 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.1.tar.gz
Algorithm Hash digest
SHA256 b0150356142632180b5857680e5cadb01d8e8a82485bcbd29542a3c262121210
MD5 6e6be09387a82245c83118d74cabb895
BLAKE2b-256 72be9efa57f840bc16f3f2c6a2a8e7c3cfca64c3367a0685944da7f79440f745

See more details on using hashes here.

File details

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

File metadata

  • Download URL: esmoe-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6702ea910134bd332499a3c03eaa5ea5f0f65693fabe9fcbe2724bed1a451812
MD5 963d7d1ae316a38eca8ba67bad7c73e1
BLAKE2b-256 2ea3d0b6fb03b6cdacd585012dc84e0e6d2af0fb9d79f98f3d2b214025d200ac

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

0.1.2

2 files

This release

0.1.1 This release

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