Compare commits
9 Commits
147959b49d
...
88215c73a8
| Author | SHA1 | Date |
|---|---|---|
|
|
88215c73a8 | |
|
|
cc312c1cc6 | |
|
|
e2ee878519 | |
|
|
b63a9565e3 | |
|
|
1aae25911b | |
|
|
1c876435ef | |
|
|
9fa620e2e5 | |
|
|
ccb352f901 | |
|
|
99c26e9043 |
11
README.md
11
README.md
|
|
@ -230,6 +230,10 @@ minimind2系列旧模型均经过权重映射+(微调训练)QKVO线性层校
|
|||
# 克隆仓库、安装依赖
|
||||
git clone --depth 1 https://github.com/jingyaogong/minimind
|
||||
cd minimind && pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
|
||||
#部分老版本Windows powershell不能识别&&,Windows用户应将&&链式命令改为分行写法
|
||||
git clone --depth 1 https://github.com/jingyaogong/minimind
|
||||
cd minimind
|
||||
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
|
||||
```
|
||||
|
||||
## Ⅰ 🚀 模型推理
|
||||
|
|
@ -242,6 +246,13 @@ cd minimind && pip install -r requirements.txt -i https://mirrors.aliyun.com/pyp
|
|||
modelscope download --model gongjy/minimind-3 --local_dir ./minimind-3
|
||||
# 方式2
|
||||
git clone https://huggingface.co/jingyaogong/minimind-3
|
||||
# 国内网络进入huggingface网站存在困难,可使用镜像站
|
||||
# Windows
|
||||
$env:HF_ENDPOINT = "https://hf-mirror.com"
|
||||
git clone https://hf-mirror.com/jingyaogong/minimind-3
|
||||
#Linux
|
||||
export HF_ENDPOINT="https://hf-mirror.com"
|
||||
git clone https://hf-mirror.com/jingyaogong/minimind-3
|
||||
```
|
||||
|
||||
### 2' CLI 推理
|
||||
|
|
|
|||
|
|
@ -229,6 +229,10 @@ After this update, maintenance for the entire `minimind-v1` series will be disco
|
|||
# Clone repository and install dependencies
|
||||
git clone --depth 1 https://github.com/jingyaogong/minimind
|
||||
cd minimind && pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
|
||||
#Tip:Some older versions of Windows PowerShell (v5.1 and below) do not recognize the && operator.
|
||||
git clone --depth 1 https://github.com/jingyaogong/minimind
|
||||
cd minimind
|
||||
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
|
||||
```
|
||||
|
||||
## Ⅰ 🚀 Model Inference
|
||||
|
|
|
|||
|
|
@ -91,4 +91,7 @@ def main():
|
|||
print(f'\n[Speed]: {gen_tokens / (time.time() - st):.2f} tokens/s\n\n') if args.show_speed else print('\n\n')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
try:
|
||||
main()
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
print()
|
||||
|
|
@ -158,7 +158,12 @@ class MOEFeedForward(nn.Module):
|
|||
x_flat = x.view(-1, hidden_dim)
|
||||
scores = F.softmax(self.gate(x_flat), dim=-1)
|
||||
topk_weight, topk_idx = torch.topk(scores, k=self.config.num_experts_per_tok, dim=-1, sorted=False)
|
||||
if self.config.norm_topk_prob: topk_weight = topk_weight / (topk_weight.sum(dim=-1, keepdim=True) + 1e-20)
|
||||
if self.config.norm_topk_prob:
|
||||
if self.config.num_experts_per_tok > 1:
|
||||
topk_weight = topk_weight / (topk_weight.sum(dim=-1, keepdim=True) + 1e-20)
|
||||
else:
|
||||
top1 = torch.topk(F.softmax(self.gate(x_flat.detach()), dim=-1), k=1, dim=-1, sorted=False)[0]
|
||||
topk_weight = top1 - top1.detach() + 1.0 # k=1: 1.0 forward on purpose, gradient via straight-through
|
||||
y = torch.zeros_like(x_flat)
|
||||
for i, expert in enumerate(self.experts):
|
||||
mask = (topk_idx == i)
|
||||
|
|
|
|||
Loading…
Reference in New Issue