MCPcopy Index your code
hub / github.com/JieShibo/MoLE

github.com/JieShibo/MoLE @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
2,468 symbols 7,949 edges 242 files 1,136 documented · 46%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

MoLE

Official code of ''Mixture of Lookup Experts''.

MoLE is a novel edge-friendly LLM architecture. With the same number of activated parameters, MoLE achieves: + Latency and memory overhead comparable to dense models + Performance on par with Mixture-of-Experts (MoE) models.

Environment

  • torch 2.0.1
  • transformers 4.38.2

Pretraining

Please refer to pretrain folder.

Models

Dense Models

  • modeling_dense.py

Moe Models

  • modeling_moe.py

MoLE Models

  • modeling_mole.py (for training)
  • modeling_mole_rep.py (for inference)

Checkpoints

All these models are trained on a 100B-token subset of the Pile dataset.

For the MoLE model, we only provide the checkpoints before re-parameterization (i.e., for the training phase). Re-parameterization can be performed using the script provided below.

Models # Activated Params URL
Dense 160M 🤗 JieShibo/Dense-160M
MoE-10E 160M 🤗 JieShibo/MoE-160M-10E
MoLE-4E 160M 🤗 JieShibo/MoLE-160M-4E
MoE-34E 160M 🤗 JieShibo/MoE-160M-34E
MoLE-16E 160M 🤗 JieShibo/MoLE-160M-16E
Dense 410M 🤗 JieShibo/Dense-410M
MoE-10E 410M 🤗 JieShibo/MoE-410M-10E
MoLE-4E 410M 🤗 JieShibo/MoLE-410M-4E

Reparameterize MoLE for Inference

python reparameterize.py --from_path <training_model_path> --to_path <inference_model_path>

Inference

from transformers import AutoTokenizer
from modeling_mole_rep import MoleForCausalLM
model = MoleForCausalLM.from_pretrained(model_path, device_map='cuda')
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
inputs = tokenizer("Hello, I am", return_tensors="pt").to(model.device)
tokens = model.generate(**inputs, max_length=10)
print(tokenizer.decode(tokens[0]))

Note that since the offloading of LUTs involves the support of the file system, the above demo still puts LUTs in the GPU memory. Alternatively, you can try the following demo, which offloads LUTs to CPU memory. This demo has not been specially optimized, so there may be some inefficiencies.

from transformers import AutoTokenizer
from modeling_mole_rep import MoleForCausalLM
model = MoleForCausalLM.from_pretrained(model_path, device_map='cpu')
model.model.embed_tokens.cuda()
model.model.layers.cuda()
model.model.norm.cuda()
model.lm_head.cuda()
model.model._buffers["causal_mask"] = model.model._buffers["causal_mask"].cuda()
model.model.moe_table.weight.data = model.model.moe_table.weight.data.pin_memory()
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
inputs = tokenizer("Hello, I am", return_tensors="pt").to('cuda')
tokens = model.generate(**inputs, max_length=10)
print(tokenizer.decode(tokens[0]))

Citation

@article{jie2025mole,
  title={Mixture of Lookup Experts},
  author={Jie, Shibo and Tang, Yehui and Han, Kai and Li, Yitong and Tang, Duyu and Deng, Zhi-Hong and Wang, Yunhe},
  journal={arXiv preprint arXiv:2503.15798},
  year={2025}
}

Core symbols most depended-on inside this repo

size
called by 200
pretrain/megatron/core/datasets/indexed_dataset.py
get_args
called by 110
pretrain/megatron/training/global_vars.py
print_rank_0
called by 104
pretrain/megatron/training/utils.py
log_single_rank
called by 57
pretrain/megatron/core/datasets/utils.py
log_retro_rank_0
called by 44
pretrain/megatron/core/datasets/retro/utils.py
start
called by 41
pretrain/megatron/core/timers.py
stop
called by 39
pretrain/megatron/core/timers.py
is_initialized
called by 34
pretrain/megatron/core/tensor_parallel/random.py

Shape

Method 1,329
Function 781
Class 358

Languages

Python100%
C++1%

Modules by API surface

pretrain/megatron/training/tokenizer/tokenizer.py97 symbols
pretrain/megatron/core/tensor_parallel/mappings.py71 symbols
modeling_mole_rep.py64 symbols
modeling_mole.py64 symbols
modeling_moe.py64 symbols
modeling_dense.py64 symbols
pretrain/megatron/core/parallel_state.py61 symbols
pretrain/megatron/core/optimizer/optimizer.py61 symbols
pretrain/megatron/legacy/model/transformer.py52 symbols
pretrain/megatron/legacy/model/vision/esvit_swin_backbone.py48 symbols
pretrain/megatron/core/optimizer/distrib_optimizer.py44 symbols
pretrain/megatron/legacy/model/vision/mit_backbone.py42 symbols

For agents

$ claude mcp add MoLE \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact