Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/utils/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ void load_tensors(std::map<std::string, torch::Tensor>& tensor_map,
torch::serialize::InputArchive archive;
archive.load_from(filename);
for (auto& pair : tensor_map) {
archive.read(pair.first, pair.second);
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
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
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.
}
}

Expand Down
Loading