| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | |
| 5 | from transformers import PreTrainedConfig |
| 6 | |
| 7 | |
| 8 | class MLPSpeculatorConfig(PreTrainedConfig): |
| 9 | model_type = "mlp_speculator" |
| 10 | |
| 11 | attribute_map = { |
| 12 | "hidden_size": "emb_dim", |
| 13 | } |
| 14 | |
| 15 | def __init__( |
| 16 | self, |
| 17 | vocab_size: int = 32000, |
| 18 | emb_dim: int = 4096, |
| 19 | inner_dim: int = 0, |
| 20 | n_predict: int = 3, |
| 21 | top_k_tokens_per_head: list[int] | None = None, |
| 22 | n_candidates: int = 5, |
| 23 | tie_weights: bool = False, |
| 24 | scale_input: bool = False, |
| 25 | **kwargs, |
| 26 | ): |
| 27 | """Initialize an MLPSpeculatorConfig. |
| 28 | |
| 29 | Args: |
| 30 | vocab_size: int |
| 31 | the model vocab size |
| 32 | emb_dim: int |
| 33 | the model embedding dimension |
| 34 | inner_dim: int |
| 35 | the inner dimension of the model. If 0, will be the emb_dim. |
| 36 | n_predict: int |
| 37 | the number of lookaheads for the speculator |
| 38 | top_k_tokens_per_head: list[int] |
| 39 | Number of tokens to consider from each head when forming the |
| 40 | candidate tree. |
| 41 | For each candidate branch in the tree, head n produces topk[n] |
| 42 | additional sub-branches. |
| 43 | NOTE: This parameter is currently unused. |
| 44 | n_candidates: int |
| 45 | number of child candidates to create per sequence |
| 46 | tie_weights: bool |
| 47 | If true, use a single set of weights for every model |
| 48 | head/stage after the first. The initial projection |
| 49 | from the base model may have a different size, so that |
| 50 | stays separate. |
| 51 | scale_input: bool |
| 52 | if True, will scale the initial hidden states from |
| 53 | the base model. |
| 54 | |
| 55 | """ |
| 56 | if top_k_tokens_per_head is None: |
| 57 | top_k_tokens_per_head = [5, 4, 3] |
| 58 | assert len(top_k_tokens_per_head) == n_predict |
| 59 | self.vocab_size = vocab_size |
| 60 | self.emb_dim = emb_dim |
| 61 | self.inner_dim = inner_dim |
| 62 | self.n_predict = n_predict |
| 63 | self.top_k_tokens_per_head = top_k_tokens_per_head |
| 64 | self.n_candidates = n_candidates |
| 65 | self.num_lookahead_tokens = n_predict |
| 66 | self.tie_weights = tie_weights |
| 67 | self.scale_input = scale_input |
| 68 | |
| 69 | super().__init__(**kwargs) |