vllm.model_executor.layers.vocab_parallel_embedding
¶
Classes:
-
ParallelLMHead–Parallelized LM head.
-
UnquantizedEmbeddingMethod–Unquantized method for embeddings.
-
VocabParallelEmbedding–Embedding parallelized in the vocabulary dimension.
-
VocabParallelEmbeddingShardIndices–Indices for a shard of a vocab parallel embedding.
Functions:
-
pad_vocab_size–Pad the vocab size to the given value.
ParallelLMHead
¶
Bases: VocabParallelEmbedding
Parallelized LM head.
Output logits weight matrices used in the Sampler. The weight and bias tensors are padded to make sure they are divisible by the number of model parallel GPUs.
Parameters:
-
(num_embeddings¶int) –vocabulary size.
-
(embedding_dim¶int) –size of hidden state.
-
(bias¶bool, default:False) –whether to use bias.
-
(params_dtype¶dtype | None, default:None) –type of the parameters.
-
(org_num_embeddings¶int | None, default:None) –original vocabulary size (without LoRA).
-
(padding_size¶int, default:DEFAULT_VOCAB_PADDING_SIZE) –padding size for the vocabulary.
-
(disable_tp¶bool, default:False) –If true, tensor parallelism will be disabled for this layer.
Methods:
-
tie_weights–Tie the weights with word embeddings.
tie_weights(embed_tokens)
¶
Tie the weights with word embeddings.
UnquantizedEmbeddingMethod
¶
Bases: QuantizeMethodBase
Unquantized method for embeddings.
Methods:
-
create_weights–Create weights for embedding layer.
create_weights(layer, input_size_per_partition, output_partition_sizes, input_size, output_size, params_dtype, **extra_weight_attrs)
¶
Create weights for embedding layer.
VocabParallelEmbedding
¶
Bases: PluggableLayer
Embedding parallelized in the vocabulary dimension.
Adapted from torch.nn.Embedding, note that we pad the vocabulary size to make sure it is divisible by the number of model parallel GPUs.
In order to support various loading methods, we ensure that LoRA-added embeddings are always at the end of TP-sharded tensors. In other words, we shard base embeddings and LoRA embeddings separately (both padded), and place them in the same tensor. In this example, we will have the original vocab size = 1010, added vocab size = 16 and padding to 64. Therefore, the total vocab size with padding will be 1088 (because we first pad 1010 to 1024, add 16, and then pad to 1088). Therefore, the tensor format looks like the following: TP1, rank 0 (no sharding): |< --------BASE-------- >|< -BASE PADDING-- >|< -----LORA------ >|< -LORA PADDING-- >| corresponding token_id: | 0 | 1 | ... | 1009 | -1 | ... | -1 | 1010 | ... | 1025 | -1 | ... | -1 | index: | 0 | 1 | ... | 1009 | 1010 | ... | 1023 | 1024 | ... | 1039 | 1040 | ... | 1087 |
TP2, rank 0: |< --------------------BASE--------------------- >|< -----LORA------ >|< -LORA PADDING- >| corresponding token_id: | 0 | 1 | 2 | ... | 497 | 498 | ... | 511 | 1010 | ... | 1025 | -1 | ... | -1 | index: | 0 | 1 | 2 | ... | 497 | 498 | ... | 511 | 512 | ... | 527 | 528 | ... | 543 | TP2, rank 1: |< -----------BASE----------- >|< -BASE PADDING- >|< -----------LORA PADDING----------- >| corresponding token_id: | 512 | 513 | 514 | ... | 1009 | -1 | ... | -1 | -1 | ... | -1 | -1 | ... | -1 | index: | 0 | 1 | 2 | ... | 497 | 498 | ... | 511 | 512 | ... | 527 | 528 | ... | 543 |
Parameters:
-
(num_embeddings¶int) –vocabulary size.
-
(embedding_dim¶int) –size of hidden state.
-
(params_dtype¶dtype | None, default:None) –type of the parameters.
-
(org_num_embeddings¶int | None, default:None) –original vocabulary size (without LoRA).
-
(padding_size¶int, default:DEFAULT_VOCAB_PADDING_SIZE) –padding size for the vocabulary.
-
(quant_config¶QuantizationConfig | None, default:None) –quant config for the layer
-
(prefix¶str, default:'') –full name of the layer in the state dict
-
(disable_tp¶bool, default:False) –If true, tensor parallelism will be disabled for this layer.
-
(reduce_results¶bool, default:True) –Whether to all-reduce contributions from vocabulary shards.
-
(quant_method¶QuantizeMethodBase | None, default:None) –Preselected quantization method for model-specific layers.
-
(parallel_group¶GroupCoordinator | None, default:None) –Process group used to shard and reduce the embedding.
Methods:
-
forward–Look up IDs, optionally reducing contributions from vocabulary shards.
-
get_sharded_to_full_mapping–Get a mapping that can be used to reindex the gathered
_get_indices(vocab_size_padded, org_vocab_size_padded, vocab_size, org_vocab_size, tp_rank, tp_size)
classmethod
¶
Get start and end indices for vocab parallel embedding, following the layout outlined in the class docstring, based on the given tp_rank and tp_size.
forward(input_)
¶
Look up IDs, optionally reducing contributions from vocabulary shards.
get_sharded_to_full_mapping()
¶
Get a mapping that can be used to reindex the gathered logits for sampling.
During sampling, we gather logits from all ranks. The relationship of index->token_id will follow the same format as outlined in the class docstring. However, after the gather, we want to reindex the final logits tensor to map index->token_id one-to-one (the index is always equal the token_id it corresponds to). The indices returned by this method allow us to do that.
VocabParallelEmbeddingShardIndices
dataclass
¶
Indices for a shard of a vocab parallel embedding.
pad_vocab_size(vocab_size, pad_to=DEFAULT_VOCAB_PADDING_SIZE)
¶
Pad the vocab size to the given value.