Skip to main content

Enhanced Mixture of Experts implementation with optimized Straight-Through Estimator router

Project description

DenseMixer

Enhanced Mixture of Experts implementation with optimized router for multiple MoE models.

Supported Models

  • Qwen3-MoE
  • Qwen2-MoE
  • OLMoE

Installation

Basic Installation

pip install densemixer

Auto-Patching Setup (Recommended)

To enable DenseMixer automatically for all Python scripts (without needing to add any import):

densemixer setup
export DENSEMIXER_ENABLED=1

This will append the necessary auto-import logic to your usercustomize.py in your user site-packages (if not already present). Any Python process with DENSEMIXER_ENABLED=1 will auto-load DenseMixer and patch transformers models.

To disable, either unset the environment variable or manually remove the relevant lines from your usercustomize.py in your user site-packages.

Usage

Basic Usage

from transformers import Qwen3MoeForCausalLM

model = Qwen3MoeForCausalLM.from_pretrained("Qwen/Qwen3-MoE-15B-A2B")

Logging

DenseMixer provides intelligent logging that informs you when custom forward methods are being used. The logging system is designed to be non-intrusive:

  • One-time logging: Each model type logs only once when its custom forward method is first used
  • Configurable: Uses Python's standard logging system
  • Informative: Clear messages indicate which models are using DenseMixer enhancements

Logging Output

When DenseMixer patches are applied, you'll see messages like:

INFO - densemixer - DenseMixer: Using custom forward method for Qwen3-MoE
INFO - densemixer - DenseMixer: Using custom forward method for OLMoE

Customizing Logging

You can customize the logging level and format:

import logging

# Set logging level
logging.getLogger("densemixer").setLevel(logging.INFO)

# Or disable logging entirely
logging.getLogger("densemixer").setLevel(logging.WARNING)

Configuration

DenseMixer can be controlled with environment variables:

Variable Default Description
DENSEMIXER_ENABLED 1 Master switch to enable/disable DenseMixer
DENSEMIXER_QWEN3 1 Enable for Qwen3-MoE models
DENSEMIXER_QWEN2 1 Enable for Qwen2-MoE models
DENSEMIXER_OLMOE 1 Enable for OLMoE models

Examples

Disable DenseMixer completely:

export DENSEMIXER_ENABLED=0
python your_script.py

Only enable for Qwen3-MoE:

export DENSEMIXER_ENABLED=1
export DENSEMIXER_QWEN3=1
export DENSEMIXER_QWEN2=0
export DENSEMIXER_OLMOE=0
python your_script.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

densemixer-0.1.1.post0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

densemixer-0.1.1.post0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file densemixer-0.1.1.post0.tar.gz.

File metadata

  • Download URL: densemixer-0.1.1.post0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for densemixer-0.1.1.post0.tar.gz
Algorithm Hash digest
SHA256 afa6dc543ad8a97a636e0bcd6d62d417c9af9be8dd5f22e236fc52240dd312b3
MD5 4e104056d51360e43596fb1387e9014d
BLAKE2b-256 2ab4094e12128ec89053e2a651da3eeedeef335fdc22d0bb10936335efe88db3

See more details on using hashes here.

File details

Details for the file densemixer-0.1.1.post0-py3-none-any.whl.

File metadata

File hashes

Hashes for densemixer-0.1.1.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfb4a7b99c56aa496e1a9b645fd50565771106fb19a9bb7f9fb6debd9f584b6b
MD5 8af230cbcb87a536f30deb58bc8222b0
BLAKE2b-256 3aa8c081e00b547803b5e9d5bb90eb12d2d691a71889ae90916eb0999ae529f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page