Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rust] Load model on given device #3419

Merged
merged 4 commits into from
Aug 16, 2024
Merged

Conversation

xyang16
Copy link
Contributor

@xyang16 xyang16 commented Aug 16, 2024

Description

Brief description of what this PR is about

  • If this change is a backward incompatible change, why must this change be made?
  • Interesting edge cases to note here

@xyang16 xyang16 requested review from zachgk, frankfliu and a team as code owners August 16, 2024 01:57
@@ -22,7 +22,7 @@ private RustLibrary() {}

public static native boolean isCudaAvailable();

public static native long loadModel(String modelPath, int dtype);
public static native long loadModel(String modelPath, int dtype, String device);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we use String, can we just use device id?

Copy link
Contributor Author

@xyang16 xyang16 Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how to distinguish cpu and cuda?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static native long loadModel(String modelPath, int dtype, int deviceType, int deviceId);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -234,3 +234,21 @@ pub extern "system" fn Java_ai_djl_engine_rust_RustLibrary_runInference<'local>(
}
}
}

pub fn as_device(device: &String) -> Result<Device> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we re-use existing as_device()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have modified the existing as_device() a little bit, please review.

@@ -22,7 +22,7 @@ private RustLibrary() {}

public static native boolean isCudaAvailable();

public static native long loadModel(String modelPath, int dtype);
public static native long loadModel(String modelPath, int dtype, String device);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xyang16 xyang16 force-pushed the rust branch 4 times, most recently from 5a010fd to 36302fb Compare August 16, 2024 16:30
.get_string(&model_path)
.expect("Couldn't get java string!")
.into();
let dtype = as_data_type(dtype).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let dtype = as_data_type(dtype).unwrap();
let dtype = as_data_type(dtype)?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@xyang16 xyang16 merged commit 71a789b into deepjavalibrary:master Aug 16, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants