# moetutel **Repository Path**: gp513/moetutel ## Basic Information - **Project Name**: moetutel - **Description**: Moe高性能库Tutel适配 - **Primary Language**: Python - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-11-07 - **Last Updated**: 2023-11-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MoeTutel ## 编译 - source cann包里的环境变量 - 进入根目录 ```shell python3 setup.py build ``` 生成whl包 ```shell python3 setup.py bdist_wheel ``` ## 安装 ```shell pip3 install dist/moe_tutel-1.0.0-cp37-cp37m-linux_aarch.whl --force-reinstall ``` ## 用例 ```python import torch import torch_npu from moetutel import npu_moe_tutel batch_size = 2 sample_size = 5 hidden = 8 capacity = 6 # x.shape = [samples, hidden] x = torch.randn(sample_size, hidden) # gates.shape = indices.shape = locations.shape = [batch, samples] gates = torch.randn(batch_size, sample_size) indices = torch.randint(0, batch_size, (batch_size, sample_size)).int() locations = torch.arange(0, sample_size).reshape(1, sample_size).int() zeros = torch.zeros([batch_size, sample_size]) locations = zeros + locations locations = locations.int() # output.shape = [batch, capacity, hidden] output = npu_moe_tutel(x.npu(), gates.npu(), indices.npu(), locations.npu(), capacity) ```