vllm.models.kimi_k3.nvidia.model ¶
Kimi-K3 multimodal model implementation for vLLM.
Classes:
-
KimiK3ForConditionalGeneration–Kimi-K3 model with Kimi-K2.5 vision and KimiLinear text.
-
KimiK3MegaMoEExperts–Kimi K3 adapter for the DeepGEMM MegaMoE kernel.
-
KimiMLP–Dense / shared-expert MLP, optionally TP-sharded under sequence parallel.
-
KimiMoE– -
KimiRoutedOutputTransform–
Functions:
-
shard_sequence_parallel_mlp–Whether to TP-shard a sequence-parallel MLP instead of replicating it.
KimiK3ForConditionalGeneration ¶
Bases: Module, SupportsMultiModal, SupportsEncoderCudaGraph, SupportsPP, SupportsQuant, SupportsEagle3, HasInnerState, IsHybrid
Kimi-K3 model with Kimi-K2.5 vision and KimiLinear text.
Source code in vllm/models/kimi_k3/nvidia/model.py
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 | |
KimiK3MegaMoEExperts ¶
Bases: DeepseekV4MegaMoEExperts
Kimi K3 adapter for the DeepGEMM MegaMoE kernel.
Source code in vllm/models/kimi_k3/nvidia/model.py
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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 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 | |
KimiMLP ¶
Bases: Module
Dense / shared-expert MLP, optionally TP-sharded under sequence parallel.
Under sequence parallelism each rank owns a distinct slice of the tokens, so by default both projections are replicated (disable_tp) and the block needs no collective. That makes every rank stream the entire weight to serve its own token shard.
With VLLM_KIMI_K3_SHARD_SP_SHARED_EXPERT the weights are TP-sharded instead. A rank then holds only a slice of the intermediate dim, so it cannot finish its own tokens alone: forward all-gathers the full token set, computes this rank's partial, and reduce-scatters. The reduce-scatter sums across TP and restores the sequence sharding in one collective, so the block still ends with one collective per direction.
Source code in vllm/models/kimi_k3/nvidia/model.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
KimiMoE ¶
Bases: Module
Source code in vllm/models/kimi_k3/nvidia/model.py
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 603 604 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 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
_maybe_overlap_router_and_down_proj(hidden_states) ¶
Compute the routed-expert down projection alongside the router, overlapping them on separate CUDA streams when latent MoE is enabled.
The router gate and the down projection both read hidden_states, so the gate runs on the default stream and the down projection on the aux stream, joined via maybe_execute_in_parallel. For MegaMoE the grouped top-k selection consumes only the gate logits, so it also runs on the default stream and overlaps the down projection.
Returns:
-
Tensor–(routed_hidden_states, router_output, topk_ids). -
Tensor–routed_hidden_statesis the down-projected latent (or the -
Tensor | None–original
hidden_stateswhen latent MoE is disabled). For MegaMoE -
tuple[Tensor, Tensor, Tensor | None]–router_outputholds the grouped top-k weights andtopk_ids -
tuple[Tensor, Tensor, Tensor | None]–the selected experts; otherwise
router_outputholds the raw gate -
tuple[Tensor, Tensor, Tensor | None]–logits and
topk_idsisNone.
Source code in vllm/models/kimi_k3/nvidia/model.py
KimiRoutedOutputTransform ¶
Bases: Module
Methods:
-
forward–Project the routed latent back to the hidden dim.
Source code in vllm/models/kimi_k3/nvidia/model.py
forward(hidden_states, residual=None) ¶
Project the routed latent back to the hidden dim.
Parameters:
-
(hidden_states¶Tensor) –Routed expert output in latent space.
-
(residual¶Tensor | None, default:None) –Optional tensor of the up-projection's output shape to accumulate into. It is consumed in the GEMM's beta-add epilogue, so adding it costs no extra kernel.
Source code in vllm/models/kimi_k3/nvidia/model.py
shard_sequence_parallel_mlp(hidden_size, intermediate_size, use_sequence_parallel, eligible) ¶
Whether to TP-shard a sequence-parallel MLP instead of replicating it.
Opt-in via VLLM_KIMI_K3_SHARD_SP_SHARED_EXPERT; see :class:KimiMLP for the trade-off and :mod:vllm.envs for when it is worth enabling.