Upload folder using huggingface_hub
Browse files- config.json +80 -0
- modeling_speculative_qwen3.py +51 -0
config.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Qwen3ForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"auto_map": {
|
| 8 |
+
"AutoModelForCausalLM": "modeling_speculative_qwen3.SpeculativeQwen3ForCausalLM"
|
| 9 |
+
},
|
| 10 |
+
"bos_token_id": 151643,
|
| 11 |
+
"draft_layers": 1,
|
| 12 |
+
"dtype": "float32",
|
| 13 |
+
"eos_token_id": 151645,
|
| 14 |
+
"head_dim": 128,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"hidden_size": 2560,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 9728,
|
| 19 |
+
"layer_types": [
|
| 20 |
+
"full_attention",
|
| 21 |
+
"full_attention",
|
| 22 |
+
"full_attention",
|
| 23 |
+
"full_attention",
|
| 24 |
+
"full_attention",
|
| 25 |
+
"full_attention",
|
| 26 |
+
"full_attention",
|
| 27 |
+
"full_attention",
|
| 28 |
+
"full_attention",
|
| 29 |
+
"full_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"full_attention",
|
| 32 |
+
"full_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"full_attention",
|
| 35 |
+
"full_attention",
|
| 36 |
+
"full_attention",
|
| 37 |
+
"full_attention",
|
| 38 |
+
"full_attention",
|
| 39 |
+
"full_attention",
|
| 40 |
+
"full_attention",
|
| 41 |
+
"full_attention",
|
| 42 |
+
"full_attention",
|
| 43 |
+
"full_attention",
|
| 44 |
+
"full_attention",
|
| 45 |
+
"full_attention",
|
| 46 |
+
"full_attention",
|
| 47 |
+
"full_attention",
|
| 48 |
+
"full_attention",
|
| 49 |
+
"full_attention",
|
| 50 |
+
"full_attention",
|
| 51 |
+
"full_attention",
|
| 52 |
+
"full_attention",
|
| 53 |
+
"full_attention",
|
| 54 |
+
"full_attention",
|
| 55 |
+
"full_attention"
|
| 56 |
+
],
|
| 57 |
+
"max_position_embeddings": 262144,
|
| 58 |
+
"max_window_layers": 36,
|
| 59 |
+
"model_type": "qwen3",
|
| 60 |
+
"num_attention_heads": 32,
|
| 61 |
+
"num_hidden_layers": 0,
|
| 62 |
+
"num_hidden_layers_free": 36,
|
| 63 |
+
"num_key_value_heads": 8,
|
| 64 |
+
"ploss_w": 0.1,
|
| 65 |
+
"rms_norm_eps": 1e-06,
|
| 66 |
+
"rope_scaling": null,
|
| 67 |
+
"rope_theta": 5000000,
|
| 68 |
+
"skip_first_input_layernorm": true,
|
| 69 |
+
"skip_output_norm": true,
|
| 70 |
+
"sliding_window": null,
|
| 71 |
+
"speculative_decoding_algorithm": "EagleV2",
|
| 72 |
+
"speculative_decoding_base_model_path": "Qwen/Qwen3-4B-Instruct-2507",
|
| 73 |
+
"speculative_decoding_draft_model": "Qwen3MoeDrafter",
|
| 74 |
+
"tie_word_embeddings": true,
|
| 75 |
+
"transformers_version": "4.56.1",
|
| 76 |
+
"use_cache": true,
|
| 77 |
+
"use_sliding_window": false,
|
| 78 |
+
"vloss_w": 1.0,
|
| 79 |
+
"vocab_size": 151936
|
| 80 |
+
}
|
modeling_speculative_qwen3.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers.models.qwen3.modeling_qwen3 import *
|
| 3 |
+
from specforge_het.specforge_lm import SpecForgeLM
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Qwen3Drafter(Qwen3Model):
|
| 7 |
+
def __init__(self, draft_config, base_model):
|
| 8 |
+
draft_config.num_hidden_layers = base_model.config.draft_layers
|
| 9 |
+
draft_config.hidden_size = base_model.get_hidden_size()
|
| 10 |
+
super().__init__(draft_config)
|
| 11 |
+
|
| 12 |
+
if base_model.config.skip_first_input_layernorm:
|
| 13 |
+
layer = self.layers[0]
|
| 14 |
+
delattr(layer, 'input_layernorm')
|
| 15 |
+
layer.input_layernorm = torch.nn.Identity()
|
| 16 |
+
|
| 17 |
+
if base_model.config.skip_output_norm:
|
| 18 |
+
delattr(self, 'norm')
|
| 19 |
+
self.norm = torch.nn.Identity()
|
| 20 |
+
|
| 21 |
+
delattr(self, 'embed_tokens')
|
| 22 |
+
|
| 23 |
+
def get_hidden_size(self):
|
| 24 |
+
return self.config.hidden_size
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class SpeculativeQwen3ForCausalLM(SpecForgeLM, Qwen3ForCausalLM):
|
| 28 |
+
@property
|
| 29 |
+
def base_model(self):
|
| 30 |
+
return self.model
|
| 31 |
+
|
| 32 |
+
def get_hidden_size(self):
|
| 33 |
+
return self.config.hidden_size
|
| 34 |
+
|
| 35 |
+
def get_base_layers(self):
|
| 36 |
+
return self.base_model.layers
|
| 37 |
+
|
| 38 |
+
def get_token_embedding(self, input_ids):
|
| 39 |
+
return self.base_model.embed_tokens(input_ids)
|
| 40 |
+
|
| 41 |
+
def get_positional_embedding(self, t, position_ids):
|
| 42 |
+
return self.base_model.rotary_emb(t, position_ids)
|
| 43 |
+
|
| 44 |
+
def get_token_logits(self, hidden_states):
|
| 45 |
+
return self.lm_head(hidden_states)
|
| 46 |
+
|
| 47 |
+
def get_max_ctx_length(self):
|
| 48 |
+
return self.model.config.max_position_embeddings
|
| 49 |
+
|
| 50 |
+
def save_pretrained(self, path, **kwargs):
|
| 51 |
+
return self.save_speculative_model(path, **kwargs)
|