Skip to content

Lazy tensor downloading in burn-remote #3276

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

Merged
merged 29 commits into from
Jun 17, 2025
Merged

Conversation

Cielbird
Copy link
Contributor

@Cielbird Cielbird commented Jun 9, 2025

No description provided.

Copy link

codecov bot commented Jun 9, 2025

Codecov Report

Attention: Patch coverage is 76.38376% with 64 lines in your changes missing coverage. Please review.

Project coverage is 82.66%. Comparing base (e02620f) to head (257e38d).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/burn-remote/src/client/channel.rs 57.14% 15 Missing ⚠️
crates/burn-remote/src/server/base.rs 75.00% 15 Missing ⚠️
crates/burn-remote/src/server/stream.rs 66.66% 12 Missing ⚠️
crates/burn-remote/src/server/processor.rs 87.50% 10 Missing ⚠️
crates/burn-remote/src/client/runner.rs 77.41% 7 Missing ⚠️
crates/burn-remote/src/server/session.rs 81.48% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3276      +/-   ##
==========================================
+ Coverage   82.51%   82.66%   +0.14%     
==========================================
  Files         990      995       +5     
  Lines      127088   127626     +538     
==========================================
+ Hits       104865   105500     +635     
+ Misses      22223    22126      -97     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

_shape: Vec<usize>,
_dtype: burn_tensor::DType,
) -> RouterTensor<Self::Client> {
let router_tensor = client.register_tensor_data(handle);
unimplemented!();
Copy link
Member

Choose a reason for hiding this comment

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

Why unimplemented?

}

impl RemoteTensorHandle {
pub(crate) fn change_backend(mut self, target_device: &WsDevice) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

I would add comments on the global strategy with the why!

Comment on lines 26 to 35
pub struct TensorUploadState {
pub data: TensorData,
pub total_upload_count: u32,
pub cur_upload_count: u32,
}

pub struct WsServerState {
pub current_uploads: Mutex<HashMap<TensorId, TensorUploadState>>,
}

Copy link
Member

Choose a reason for hiding this comment

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

I would put that in tensor_data_service.rs

};

// build our application with some routes
let app = Router::new()
.route("/response", any(Self::handler_response))
.route("/request", any(Self::handler_request))
.with_state(state);
.route("/upload", any(Self::handler_upload))
Copy link
Member

Choose a reason for hiding this comment

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

/data

Comment on lines 231 to 241
let mut upload_state;
{
let mut current_uploads = self.state.current_uploads.lock().unwrap();
if current_uploads.contains_key(&id) {
// take the upload out of the hashmap while we download
upload_state = current_uploads.remove(&id).unwrap();
log::info!("Tensor found (id: {id:?})");
} else {
panic!("A tensor was requested (id: {id:?}) that isn't being served");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

let upload_state = {
};

Comment on lines 252 to 255
if upload_state.total_upload_count != upload_state.cur_upload_count {
let mut current_uploads = self.state.current_uploads.lock().unwrap();
current_uploads.insert(id, upload_state);
}
Copy link
Member

Choose a reason for hiding this comment

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

I would do that during the first lock.


match msg {
Message::Binary(bytes) => {
let data: TensorData = rmp_serde::from_slice(&bytes)
Copy link
Member

Choose a reason for hiding this comment

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

TODO: Optimize that at some point.

Comment on lines 53 to 59
pub fn register_remote_tensor(&self, tensor: TensorNetwork, new_id: TensorId) {
self.compute_sender
.send(ProcessorTask::RegisterRemoteTensor(tensor, new_id))
.unwrap()
}

pub fn upload_tensor(&self, tensor: TensorIr, count: u32) {
Copy link
Member

Choose a reason for hiding this comment

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

Change naming

@@ -61,7 +83,7 @@ impl<B: BackendIr> Stream<B> {

self.compute_sender
.send(ProcessorTask::Sync(id, callback_sender))
.unwrap();
.unwrap_or_else(|x| println!("{x:?}"));
Copy link
Member

Choose a reason for hiding this comment

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

unwrap

@@ -0,0 +1,2451 @@
mod types {
Copy link
Member

Choose a reason for hiding this comment

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

remove

Co-authored-by: Jonathan Richard <jwric@users.noreply.github.com>
@nathanielsimard nathanielsimard merged commit 81985bd into main Jun 17, 2025
11 checks passed
@nathanielsimard nathanielsimard deleted the fix/functional-remote branch June 17, 2025 15:55
Helios113 pushed a commit to Helios113/burn that referenced this pull request Jul 1, 2025
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