Downloads · 30 days
21
8% of all-time downloads
Ndlcwx/NDLMoe_1.3B-base
NDLMoe_1.3B-base is a text generation model from Ndlcwx. Use it when you need the model to write or continue text. It is set up for transformers.
NDLMoe1.3B-base:此模型是基于约180亿tokens训练的语言模型,其框架依赖于transformer-decoder only,此模型的具体结构为: 预训练数据主要为天工数据集、百度百科、维基百科中文、维基百科英文以及github代码等。
Downloads · 30 days
21
8% of all-time downloads
All-time downloads
256
Public
Parameters
1.3B
2.6 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors2.6 GB · 100%
From the Hugging Face model README
NDLMoe_1.3B-base:此模型是基于约180亿tokens训练的语言模型,其框架依赖于transformer-decoder only,此模型的具体结构为:
预训练数据主要为天工数据集、百度百科、维基百科中文、维基百科英文以及github代码等。
此模型主要有以下特点:
$$ \begin{cases} L_{\text {ExpBal }} =\alpha {1} \sum{i=1}^{N^{\prime}} f_{i} P_{i} \ f_{i} =\frac{N^{\prime}}{K T} \sum_{t=1}^{T} 1(\text { Token } t \text { selects Expert } i) \ P_{i} =\frac{1}{T} \sum_{t=1}^{T} s_{i, t} \end{cases} $$
运行NDLMoe_1.3B-base,请确保满足上述要求,再执行以下pip命令安装依赖库
pip install transformers==4.39.3 accelerate
推荐安装flash-attn的步骤:(如果没有安装此模型也可以运行,安装了推理会更快一些。)
git clone https://github.com/Dao-AILab/flash-attention
cd flash-attention && pip install .
# 下方安装可选,安装可能比较缓慢。
# pip install csrc/layer_norm
# pip install csrc/rotary
<br>
您可以通过以下代码轻松调用:
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import GenerationConfig
tokenizer = AutoTokenizer.from_pretrained("Ndlcwx/NDLMoe_1.3B-base", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("Ndlcwx/NDLMoe_1.3B-base", device_map="auto", trust_remote_code=True).eval()
from transformers import GenerationConfig
gen_config = GenerationConfig(
temperature=0.9,
top_k=30,
top_p=0.5,
do_sample=True,
num_beams=1,
repetition_penalty=1.2,
max_new_tokens=400,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
)
prompt= '浙江省杭州市的西湖'
import torch
device = 'cuda'
tokend = tokenizer(prompt)
input_ids, attention_mask = torch.LongTensor([tokend.input_ids]).to(
device
), torch.LongTensor([tokend.attention_mask]).to(device)
outputs = model.generate(
inputs=input_ids, attention_mask=attention_mask, generation_config=gen_config
)
outs = tokenizer.decode(outputs[0].cpu().numpy())
# outs = outs.replace(prompt,'')
outs = outs.replace('[EOS]','')
print("当前SLM回答:",outs)
<br>
NDLMoe_1.3B-base模型规模基本情况如下所示:
| Hyperparameter | Value |
|---|---|
| n_layers | 12 |
| n_heads | 32 |
| d_model | 1600 |
| n_shared_experts | 2 |
| n_routed_experts | 15 |
| num_experts_per_tok | 4 |
| intermediate_size | 14336 |
| moe_intermediate_size | 1024 |
| vocab size | 60930 |
| sequence length | 512 |
本模型在位置编码、FFN激活函数和normalization的实现方式上采用了RoPE相对位置编码、SwiGLU激活函数、RMSNorm(可选安装flash-attention加速);除此之外,该模型的第一个decoder层并没有采用MOE层,而是采用了以前流行的attention+FFN的配置,MOE层的设置是从第二个layer开始的。