Skip to content

Update serialize/deserialize#69

Merged
chengcli merged 1 commit intomainfrom
cli/serialize
Jan 17, 2026
Merged

Update serialize/deserialize#69
chengcli merged 1 commit intomainfrom
cli/serialize

Conversation

@chengcli
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 17, 2026 19:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds error handling to the load_tensors function to gracefully handle missing tensors during deserialization. Instead of failing when a tensor is not found in the archive, the function now catches exceptions and continues loading remaining tensors.

Changes:

  • Wrapped archive.read() call in a try-catch block to handle c10::Error exceptions
  • Added logic to skip missing tensors silently during deserialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

try {
archive.read(pair.first, pair.second);
} catch (const c10::Error& e) {
// skip missing tensors
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The catch block catches all c10::Error exceptions, which includes many different types of errors beyond just missing tensors. This could mask serious issues like corrupted archives, I/O errors, or type mismatches. Consider checking the error type or message to only skip errors specifically related to missing tensors, and re-throw other types of errors that indicate real problems.

Suggested change
// skip missing tensors
// Only skip errors that clearly indicate a missing tensor/key.
const std::string msg = e.what();
if (msg.find("archive entry not found") == std::string::npos &&
msg.find("Could not find key") == std::string::npos &&
msg.find("Could not find tensor") == std::string::npos) {
// Unexpected error: rethrow so it can be handled by the caller.
throw;
}
// Known missing-tensor error: skip this entry.

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +27
try {
archive.read(pair.first, pair.second);
} catch (const c10::Error& e) {
// skip missing tensors
}
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The load_tensors function's behavior has fundamentally changed - it now silently skips missing tensors instead of failing. This is a significant change to the API contract that should be documented. Consider adding a comment to the function header in serialize.hpp explaining that missing tensors will be silently skipped, or alternatively, consider whether the caller should have control over this behavior through an optional parameter.

Copilot uses AI. Check for mistakes.
Comment on lines +25 to +27
} catch (const c10::Error& e) {
// skip missing tensors
}
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The catch block silently suppresses all errors without any logging or feedback. This makes debugging difficult when tensors fail to load unexpectedly. Consider logging at least a warning with the tensor name and error details to help diagnose issues. For example, you could add a log statement indicating which tensor was not found in the archive.

Copilot uses AI. Check for mistakes.
@chengcli chengcli merged commit e44662b into main Jan 17, 2026
9 checks passed
@chengcli chengcli deleted the cli/serialize branch January 17, 2026 20:15
@github-actions
Copy link

🎉 Released v1.2.9!

What's Changed

Full Changelog: v1.2.8...v1.2.9

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.

1 participant