Views
No views yet
environment.yml for all dependencies.Note: Some scripts may require additional dependencies (e.g.,matplotlib,pandas).
--model_index (see also HybridTensor/utils/activations.py):| Index | Model Name |
|---|---|
| 5 | facebook/opt-6.7b |
| 8 | facebook/opt-66b |
| 11 | meta-llama/Llama-2-7b-hf |
| 15 | meta-llama/Llama-3.1-70B |
HybridTensor/routers/datacollection/data_collection.pyHybridTensor/routers/mlp/main_mlp.pyHybridTensor/routers/mha/main_att.pyHybridTensor/benchmarks/model_eval.pyHybridTensor/triton/run_sparse_mlp.py, run_sparse_attn.py, run_sparse_transformer_block.pymodel_sparse_generation.pyenvironment.yml for details).conda env create -f environment.ymlpip install -U --index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/Triton-Nightly/pypi/simple/ triton-nightly1python -m HybridTensor.routers.datacollection.data_collection \
2 --model_index 5 \
3 --batch_size 8 \
4 --device_map auto \
5 --data_dir <PATH_TO_ACTIVATION_DATA> \
6 --max_samples 400000 \
7 --model_family <opt/llama> \
8 --mlp_activation True \
9 --attn_norm True--model_index: Index of the model to use (see HybridTensor/utils/activations.py for available indices).--batch_size: Number of samples per batch during data collection, adjust to configure GPU memory usage.--data_dir: Directory to save the collected activation data.--model_family: Model family (e.g., opt, llama).--mlp_activation: Set to True to collect MLP activation data. Only for sparse MLP models.--attn_norm: Set to True to collect attention norm data.1python -m HybridTensor.routers.mlp.main_mlp \
2 --model_index <MODEL_INDEX> \
3 --L <LAYER_NUMBER> \
4 --data_dir <PATH_TO_ACTIVATION_DATA> \
5 --ckpt_dir <PATH_TO_SAVE_CHECKPOINTS> \
6 --gpu <GPU_ID>./HybridTensor/routers/mlp/train_mlp_routers.sh1python -m HybridTensor.routers.mha.main_att \
2 --model_index <MODEL_INDEX> \
3 --L <LAYER_NUMBER> \
4 --k <TOPK_VALUE> \
5 --data_dir <PATH_TO_ACTIVATION_DATA> \
6 --ckpt_dir <PATH_TO_SAVE_CHECKPOINTS>./HybridTensor/routers/mha/train_mha_routers_topk.sh1python -m HybridTensor.routers.mlp.mlp_router_optim_fast --model_index <MODEL_INDEX> --batch_size <BATCH_SIZE_INFERENCE> --mlp_ckpt_dir <PATH_TO_MLP_ROUTER_CHECKPOINTS> --act_data_dir <PATH_TO_ACTIVATION_DATA>
2--batch_size: batch size to optimize for inferenceHybridTensor/benchmarks/model_eval.py script. Below are example commands and explanations for the main arguments. These scripts use huggingface implementations with masking for easy benchmarking. These do not use the optimized kernels for efficient inference.1python -m HybridTensor.benchmarks.model_eval \
2 --model_index <MODEL_INDEX> \
3 --batch_size <BATCH_SIZE> \
4 --mode <dense|sparse|sparse_attn> \
5 --benchmark <all|BENCHMARK_NAME> \
6 --attn_topk <TOPK_VALUE> \
7 --attn_ckpt_dir <PATH_TO_ATTENTION_ROUTER_CHECKPOINTS> \
8 --mlp_ckpt_dir <PATH_TO_MLP_ROUTER_CHECKPOINTS> \
9 --data_collection <True|False> \
10 --device auto \
11 --note <NOTE>--batch_size: Batch size to use for evaluation.--mode: Evaluation mode. Options are dense (standard), sparse (sparse MLP and/or attention using trained routers), or sparse_attn (sparse attention only using ground truth activations ,doesn't require routers).--benchmark: Which benchmark(s) to run. Use all for the full suite or specify a single benchmark (e.g., mmlu).--attn_topk: Top-k value for attention sparsity (e.g., 0.5 for 50% sparsity).--attn_ckpt_dir: Directory containing attention router checkpoints.--mlp_ckpt_dir: Directory containing MLP router checkpoints.--data_collection: Set to True to enable data collection mode for threshold sweeps.--device: Device ID to use (e.g., 0 for cuda:0).--note: Optional note to append to the results filename.HybridTensor/triton/.1python -m HybridTensor.triton.gather_gemm_col \
2 --batch_size <BATCH_SIZE> \
3 --in_features <EMBEDDING_DIMENSION> \
4 --index_size <TOTAL_ACTIVE_NEURONS>--in_features: Model embedding dimension (e.g., 8192).--index_size: Total number of active neurons selected by the router. Needs to be less than or equal to total neurons.1python run_sparse_mlp.py \
2 --in_features <EMBEDDING_DIMENSION> \
3 --batch_size <BATCH_SIZE> \
4 --index_size <ACTIVE_NEURONS>1python run_sparse_attn.py \
2 --in_features <EMBEDDING_DIMENSION> \
3 --batch_size <BATCH_SIZE> \
4 --seq_len <SEQUENCE_LENGTH> \
5 --attn_topk <TOPK_VALUE>--attn_topk: Fraction of attention heads to keep active (e.g., 0.5 for 50%).export TRITON_PRINT_AUTOTUNING="1" HybridTensor/triton/heuristics/autotune_configs.py script to compile the kernels for different batch sizes and activation to speedup inference.1python run_sparse_transformer_block.py \
2 --in_features <EMBEDDING_DIMENSION> \
3 --batch_size <BATCH_SIZE> \
4 --seq_len <SEQUENCE_LENGTH> \
5 --index_size <ACTIVE_NEURONS> \
6 --attn_topk <TOPK_VALUE>Note:
Therun_sparse_transformer_block.pyscript can also be used to simulate large-scale inferencing setups with large batch sizes and sequence lengths on a single GPU if multi-GPU system is not available, since only a single transformer layer is executed in this script.
1python -m HybridTensor.benchmarks.generation.model_sparse_generation \
2 --model_index <MODEL_INDEX> \
3 --mlp_ckpt_dir <PATH_TO_MLP_ROUTER_CHECKPOINTS> \
4 --attn_ckpt_dir <PATH_TO_ATTENTION_ROUTER_CHECKPOINTS> \
5 --batch_stats_dir <PATH_TO_BATCH_STATS> \
6 --attn_topk <TOPK_VALUE>--batch_stats_dir: used for sparse MLP models, path to the output from dynamic top-k optimization. Saved in configs/<model_name>1@misc{shrestha2025polarsparsityhighthroughput,
2 title={Polar Sparsity: High Throughput Batched LLM Inferencing with Scalable Contextual Sparsity},
3 author={Susav Shrestha and Brad Settlemyer and Nikoli Dryden and Narasimha Reddy},
4 year={2025},
5 eprint={2505.14884},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={https://arxiv.org/abs/2505.14884},
9}