Skip to content

Commit 5f14e46

Browse files
Add lazy import to nixl.py
1 parent 9162f3a commit 5f14e46

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

container/deps/vllm/vllm_v0.7.2-triton-kv-disagg-patch.patch

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,9 @@ index 00000000..bc962726
618618
+import msgspec
619619
+import time
620620
+import uuid
621-
+from nixl_wrapper import nixl_wrapper as NixlWrapper
622621
+
623622
+logger = init_logger(__name__)
624623
+
625-
+
626624
+def nixl_wrapper_init_patch(self, agent_name, nixl_config):
627625
+ logger.info("Initializing patched NixlWrapper")
628626
+ import nixl_bindings as nixl
@@ -646,9 +644,17 @@ index 00000000..bc962726
646644
+ "WRITE_NOTIF": nixl.NIXL_WR_NOTIF,
647645
+ "READ_NOTIF": nixl.NIXL_RD_NOTIF}
648646
+
649-
+ print("Initializied NIXL agent:", agent_name)
647+
+ logger.info("Initializied NIXL agent: %s", agent_name)
648+
+
650649
+
651-
+NixlWrapper.__init__ = nixl_wrapper_init_patch
650+
+# Lazy import nixl_wrapper to avoid loading nixl_bindings if nixl is not used
651+
+try:
652+
+ from nixl_wrapper import nixl_wrapper as NixlWrapper # type: ignore
653+
+ logger.info("NIXL is available")
654+
+ NixlWrapper.__init__ = nixl_wrapper_init_patch
655+
+except ImportError:
656+
+ logger.warning("NIXL is not available")
657+
+ NixlWrapper = None
652658
+
653659
+
654660
+
@@ -665,6 +671,10 @@ index 00000000..bc962726
665671
+class TritonNixlConnector:
666672
+ def __init__(self, vllm_config: VllmConfig, engine_id: str, rank: int):
667673
+ self.vllm_config = vllm_config
674+
+ if NixlWrapper is None:
675+
+ logger.error("NIXL is not available")
676+
+ raise RuntimeError("NIXL is not available")
677+
+ logger.info("Initializing NIXL wrapper")
668678
+ self.nixl_wrapper = NixlWrapper(str(uuid.uuid4()), None)
669679
+
670680
+ self.num_layers = None

examples/python_rs/llm/vllm/__init__.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/python_rs/llm/vllm/common/__init__.py

Whitespace-only changes.

examples/python_rs/llm/vllm/monolith/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)