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

pip install densemixer

Usage: Auto-Patching Setup (No Manual Import Needed)

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.

Example

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: densemixer-0.1.1.tar.gz
  • Upload date:
  • Size: 8.8 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.tar.gz
Algorithm Hash digest
SHA256 c8b22d39d093e0f1c0d79438e8d84e91d5f82b932c0781216da893b4f2350c1e
MD5 cbde885c0d6805bc5ec54c04c1005207
BLAKE2b-256 e1992637e1ec7d119866c6a303e6ae094d8822be6c4e0bfb38d16ab1f1cb458b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: densemixer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for densemixer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52d01db54d06f5a98bbb8498b7f8ca36e35b1c901f385f1b5cc8b9c57263d239
MD5 5f810c7a2fbbb741db7fd6b57e3f617f
BLAKE2b-256 0e70a9ce084ac2c7bb8504ae1300df6f1ca1f189bccabd9ad99bdf72304699d9

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