vllm.model_executor.models.phimoe
Inference-only PhiMoE model.
PhiMoE ¶
Bases: Module
A tensor-parallel MoE implementation for PhiMoE that shards each expert across all ranks.
Each expert's weights are sharded across all ranks and a fused MoE kernel is used for the forward pass, and finally we reduce the outputs across ranks.
Source code in vllm/model_executor/models/phimoe.py
experts instance-attribute
¶
experts = FusedMoE(
num_experts=num_experts,
top_k=top_k,
hidden_size=hidden_size,
intermediate_size=intermediate_size,
params_dtype=params_dtype,
reduce_results=True,
renormalize=False,
quant_config=quant_config,
tp_size=tp_size,
custom_routing_function=phimoe_routing_function,
prefix=f"{prefix}.experts",
)
gate instance-attribute
¶
gate = ReplicatedLinear(
hidden_size,
num_experts,
bias=False,
params_dtype=params_dtype,
quant_config=None,
)
__init__ ¶
__init__(
num_experts: int,
top_k: int,
hidden_size: int,
intermediate_size: int,
params_dtype: Optional[dtype] = None,
quant_config: Optional[QuantizationConfig] = None,
tp_size: Optional[int] = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/phimoe.py
forward ¶
Source code in vllm/model_executor/models/phimoe.py
PhiMoEAttention ¶
Bases: Module
Source code in vllm/model_executor/models/phimoe.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
attn instance-attribute
¶
attn = Attention(
num_heads,
head_dim,
scaling,
num_kv_heads=num_kv_heads,
cache_config=cache_config,
quant_config=quant_config,
prefix=f"{prefix}.attn",
)
o_proj instance-attribute
¶
o_proj = RowParallelLinear(
total_num_heads * head_dim,
hidden_size,
bias=True,
quant_config=quant_config,
)
qkv_proj instance-attribute
¶
qkv_proj = QKVParallelLinear(
hidden_size,
head_dim,
total_num_heads,
total_num_kv_heads,
bias=True,
quant_config=quant_config,
)
rotary_emb instance-attribute
¶
rotary_emb = get_rope(
head_dim,
rotary_dim=head_dim,
max_position=max_position,
base=int(rope_theta),
is_neox_style=True,
rope_scaling=rope_scaling,
)
__init__ ¶
__init__(
hidden_size: int,
num_heads: int,
num_kv_heads: int,
head_dim: Optional[int] = None,
max_position: int = 4096 * 32,
rope_theta: float = 10000,
cache_config: Optional[CacheConfig] = None,
quant_config: Optional[QuantizationConfig] = None,
rope_scaling: Optional[dict] = None,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/phimoe.py
forward ¶
Source code in vllm/model_executor/models/phimoe.py
PhiMoEConfig ¶
Bases: PretrainedConfig
Source code in vllm/model_executor/models/phimoe.py
keys_to_ignore_at_inference class-attribute
instance-attribute
¶
__init__ ¶
__init__(
vocab_size=32000,
hidden_size=4096,
intermediate_size=14336,
num_hidden_layers=32,
num_attention_heads=32,
num_key_value_heads=8,
head_dim=None,
hidden_act="silu",
max_position_embeddings=4096 * 32,
initializer_range=0.02,
rms_norm_eps=1e-05,
use_cache=True,
pad_token_id=None,
bos_token_id=1,
eos_token_id=2,
tie_word_embeddings=False,
rope_theta=1000000.0,
sliding_window=None,
attention_dropout=0.0,
num_experts_per_tok=2,
num_local_experts=16,
output_router_logits=False,
router_aux_loss_coef=0.001,
router_jitter_noise=0.0,
attention_bias=False,
lm_head_bias=False,
**kwargs,
)
Source code in vllm/model_executor/models/phimoe.py
PhiMoEDecoderLayer ¶
Bases: Module
Source code in vllm/model_executor/models/phimoe.py
block_sparse_moe instance-attribute
¶
block_sparse_moe = PhiMoE(
num_experts=num_local_experts,
top_k=num_experts_per_tok,
hidden_size=hidden_size,
intermediate_size=intermediate_size,
quant_config=quant_config,
prefix=f"{prefix}.block_sparse_moe",
)
input_layernorm instance-attribute
¶
input_layernorm = LayerNorm(
hidden_size, eps=rms_norm_eps, elementwise_affine=True
)
post_attention_layernorm instance-attribute
¶
post_attention_layernorm = LayerNorm(
hidden_size, eps=rms_norm_eps, elementwise_affine=True
)
self_attn instance-attribute
¶
self_attn = PhiMoEAttention(
hidden_size=hidden_size,
num_heads=num_attention_heads,
max_position=max_position_embeddings,
num_kv_heads=num_key_value_heads,
head_dim=getattr(
config,
"head_dim",
hidden_size // num_attention_heads,
),
rope_theta=rope_theta,
cache_config=cache_config,
quant_config=quant_config,
rope_scaling=rope_scaling,
prefix=f"{prefix}.self_attn",
)
__init__ ¶
__init__(
config: PhiMoEConfig,
cache_config: Optional[CacheConfig] = None,
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/phimoe.py
forward ¶
Source code in vllm/model_executor/models/phimoe.py
PhiMoEForCausalLM ¶
Bases: Module
, SupportsLoRA
, SupportsPP
Source code in vllm/model_executor/models/phimoe.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
|
embedding_modules class-attribute
instance-attribute
¶
embedding_padding_modules class-attribute
instance-attribute
¶
fall_back_to_pt_during_load class-attribute
instance-attribute
¶
lm_head instance-attribute
¶
lm_head = ParallelLMHead(
unpadded_vocab_size,
hidden_size,
org_num_embeddings=vocab_size,
padding_size=DEFAULT_VOCAB_PADDING_SIZE
if not lora_config
else lora_vocab_padding_size,
quant_config=None,
bias=True,
)
logits_processor instance-attribute
¶
logits_processor = LogitsProcessor(
unpadded_vocab_size, vocab_size
)
make_empty_intermediate_tensors instance-attribute
¶
model instance-attribute
¶
model = PhiMoEModel(
vllm_config=vllm_config,
prefix=maybe_prefix(prefix, "model"),
)
packed_modules_mapping class-attribute
instance-attribute
¶
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/phimoe.py
compute_logits ¶
compute_logits(
hidden_states: Tensor,
sampling_metadata: SamplingMetadata,
) -> Tensor
forward ¶
forward(
input_ids: Tensor,
positions: Tensor,
intermediate_tensors: Optional[
IntermediateTensors
] = None,
inputs_embeds: Optional[Tensor] = None,
) -> Union[Tensor, IntermediateTensors]
Source code in vllm/model_executor/models/phimoe.py
get_expert_mapping ¶
get_input_embeddings ¶
PhiMoEModel ¶
Bases: Module
Source code in vllm/model_executor/models/phimoe.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
|
embed_tokens instance-attribute
¶
embed_tokens = VocabParallelEmbedding(
vocab_size, hidden_size, org_num_embeddings=vocab_size
)
make_empty_intermediate_tensors instance-attribute
¶
make_empty_intermediate_tensors = (
make_empty_intermediate_tensors_factory(
["hidden_states", "residual"], hidden_size
)
)
norm instance-attribute
¶
norm = LayerNorm(
hidden_size, eps=rms_norm_eps, elementwise_affine=True
)
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/phimoe.py
forward ¶
forward(
input_ids: Tensor,
positions: Tensor,
intermediate_tensors: Optional[IntermediateTensors],
inputs_embeds: Optional[Tensor] = None,
) -> Union[Tensor, IntermediateTensors]
Source code in vllm/model_executor/models/phimoe.py
get_expert_mapping ¶
Source code in vllm/model_executor/models/phimoe.py
get_input_embeddings ¶
load_weights ¶
Source code in vllm/model_executor/models/phimoe.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
|
mp ¶
Bases: Function
Source code in vllm/model_executor/models/phimoe.py
backward staticmethod
¶
backward(ctx, grad_at_output: Tensor)
Source code in vllm/model_executor/models/phimoe.py
phimoe_routing_function ¶
phimoe_routing_function(
hidden_states: Tensor,
gating_output: Tensor,
topk: int,
renormalize: bool,
)