Skip to content

Commit 7e071ea

Browse files
committed
feat: NIXL stub support
Signed-off-by: Alexandre Milesi <[email protected]>
1 parent 2333f15 commit 7e071ea

File tree

7 files changed

+141
-20
lines changed

7 files changed

+141
-20
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/bindings/python/Cargo.lock

Lines changed: 109 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/llm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ dialoguer = { version = "0.11", default-features = false, features = [
9797

9898
# block_manager
9999
aligned-vec = { version = "0.6.4", optional = true }
100-
nixl-sys = { version = "=0.7.0", optional = true }
100+
nixl-sys = { git = "https://github.com/ai-dynamo/nixl", rev = "ae3f8af", optional = true }
101101
cudarc = { workspace = true, optional = true }
102102
nix = { version = "0.26", optional = true }
103103

lib/llm/src/preprocessor/media/decoders/image.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ pub struct ImageMetadata {
4747
#[allow(dead_code)] // used in followup MR
4848
pub(crate) format: Option<ImageFormat>,
4949
#[allow(dead_code)] // used in followup MR
50-
pub(crate) color_type: ColorType,
51-
#[allow(dead_code)] // used in followup MR
5250
pub(crate) layout: ImageLayout,
5351
}
5452

@@ -82,7 +80,6 @@ impl Decoder for ImageDecoder {
8280
let mut decoded: DecodedMediaData = array.try_into()?;
8381
decoded.tensor_info.metadata = Some(DecodedMediaMetadata::Image(ImageMetadata {
8482
format,
85-
color_type,
8683
layout: ImageLayout::HWC,
8784
}));
8885
Ok(decoded)

lib/llm/src/preprocessor/media/loader.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct MediaLoader {
4141
media_decoder: MediaDecoder,
4242
http_client: reqwest::Client,
4343
media_fetcher: MediaFetcher,
44-
nixl_agent: NixlAgent,
44+
nixl_agent: Option<NixlAgent>,
4545
}
4646

4747
impl MediaLoader {
@@ -55,7 +55,15 @@ impl MediaLoader {
5555

5656
let http_client = http_client_builder.build()?;
5757

58-
let nixl_agent = get_nixl_agent()?;
58+
let nixl_agent = match get_nixl_agent() {
59+
Ok(agent) => Some(agent),
60+
Err(e) => {
61+
tracing::warn!(
62+
"Error when creating NIXL agent (will not be able to register media data): {e}"
63+
);
64+
None
65+
}
66+
};
5967

6068
Ok(Self {
6169
media_decoder,
@@ -96,6 +104,10 @@ impl MediaLoader {
96104
oai_content_part: &ChatCompletionRequestUserMessageContentPart,
97105
// TODO: request-level options
98106
) -> Result<RdmaMediaDataDescriptor> {
107+
if self.nixl_agent.is_none() {
108+
anyhow::bail!("NIXL agent is not available, cannot decode and register media data");
109+
}
110+
99111
// fetch the media, decode and NIXL-register
100112
let decoded = match oai_content_part {
101113
ChatCompletionRequestUserMessageContentPart::ImageUrl(image_part) => {
@@ -116,7 +128,7 @@ impl MediaLoader {
116128
_ => anyhow::bail!("Unsupported media type"),
117129
};
118130

119-
let rdma_descriptor = decoded.into_rdma_descriptor(&self.nixl_agent)?;
131+
let rdma_descriptor = decoded.into_rdma_descriptor(self.nixl_agent.as_ref().unwrap())?;
120132
Ok(rdma_descriptor)
121133
}
122134
}
@@ -148,21 +160,22 @@ mod tests {
148160
..Default::default()
149161
};
150162

151-
let loader = MediaLoader::new(media_decoder, fetcher).unwrap();
163+
let loader: MediaLoader = MediaLoader::new(media_decoder, fetcher).unwrap();
152164

153165
let image_url = ImageUrl::from(format!("{}/llm-optimize-deploy-graphic.png", server.url()));
154166
let content_part = ChatCompletionRequestUserMessageContentPart::ImageUrl(
155167
ChatCompletionRequestMessageContentPartImage { image_url },
156168
);
157169

158170
let result = loader.fetch_and_decode_media_part(&content_part).await;
159-
assert!(
160-
result.is_ok(),
161-
"Failed to fetch and decode image: {:?}",
162-
result.err()
163-
);
164-
165-
let descriptor = result.unwrap();
171+
let descriptor = match result {
172+
Ok(descriptor) => descriptor,
173+
Err(e) if e.to_string().contains("NIXL agent is not available") => {
174+
eprintln!("Skipping test: NIXL agent not available");
175+
return;
176+
}
177+
Err(e) => panic!("Failed to fetch and decode image: {}", e),
178+
};
166179
assert_eq!(descriptor.tensor_info.dtype, DataType::UINT8);
167180

168181
// Verify image dimensions: 1,999px × 1,125px (width × height)

lib/memory/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dynamo-config = { workspace = true }
2626

2727
anyhow = { workspace = true }
2828
cudarc = { workspace = true }
29-
nixl-sys = { version = "0.7" }
29+
nixl-sys = { git = "https://github.com/ai-dynamo/nixl", rev = "ae3f8af" }
3030
serde = { workspace = true}
3131
thiserror = { workspace = true }
3232
tracing = { workspace = true }

lib/memory/src/nixl/agent.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ pub struct NixlAgent {
3232
impl NixlAgent {
3333
/// Create a NIXL agent without any backends.
3434
pub fn new(name: &str) -> Result<Self> {
35+
if nixl_sys::is_stub() {
36+
return Err(anyhow::anyhow!("NIXL is stubbed, cannot create agent"));
37+
}
38+
3539
let agent = Agent::new(name)?;
3640

3741
Ok(Self {

0 commit comments

Comments
 (0)