mirror of
https://github.com/huggingface/candle.git
synced 2025-06-20 04:00:28 +00:00
Support for phi-2. (#1429)
* Support for phi-2. * Use the v2 naming scheme.
This commit is contained in:
@ -57,6 +57,22 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn v2() -> Self {
|
||||
Self {
|
||||
vocab_size: 51200,
|
||||
n_positions: 2048,
|
||||
n_embd: 2560,
|
||||
n_layer: 32,
|
||||
n_inner: None,
|
||||
n_head: 32,
|
||||
rotary_dim: usize::min(32, 2560 / 32),
|
||||
activation_function: Activation::Gelu,
|
||||
layer_norm_epsilon: 1e-5,
|
||||
tie_word_embeddings: false,
|
||||
pad_vocab_size_multiple: 64,
|
||||
}
|
||||
}
|
||||
|
||||
// https://huggingface.co/teknium/Puffin-Phi-v2/blob/main/config.json
|
||||
pub fn puffin_phi_v2() -> Self {
|
||||
Self {
|
||||
@ -372,6 +388,24 @@ pub struct MixFormerSequentialForCausalLM {
|
||||
}
|
||||
|
||||
impl MixFormerSequentialForCausalLM {
|
||||
pub fn new_v2(cfg: &Config, vb: VarBuilder) -> Result<Self> {
|
||||
let vb_head = vb.pp("lm_head");
|
||||
let vb = vb.pp("transformer");
|
||||
let embedding = Embedding::new(cfg, vb.pp("embd"))?;
|
||||
let mut blocks = Vec::new();
|
||||
for i in 0..cfg.n_layer {
|
||||
let block = ParallelBlock::new(cfg, vb.pp("h").pp(i))?;
|
||||
blocks.push(block)
|
||||
}
|
||||
let head = CausalLMHead::new(cfg, vb_head)?;
|
||||
Ok(Self {
|
||||
embedding,
|
||||
blocks,
|
||||
head,
|
||||
span: tracing::span!(tracing::Level::TRACE, "mixformer"),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new(cfg: &Config, vb: VarBuilder) -> Result<Self> {
|
||||
let vb = vb.pp("layers");
|
||||
let embedding = Embedding::new(cfg, vb.pp(0))?;
|
||||
|
Reference in New Issue
Block a user