Skip to content

Revise serialize#73

Merged
chengcli merged 2 commits intomainfrom
cli/revise_serialize
Feb 15, 2026
Merged

Revise serialize#73
chengcli merged 2 commits intomainfrom
cli/revise_serialize

Conversation

@chengcli
Copy link
Owner

No description provided.

Cheng Li and others added 2 commits February 14, 2026 17:03
Copilot AI review requested due to automatic review settings February 15, 2026 16:37
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 revises the tensor deserialization API in src/utils/serialize by changing load_tensors from an out-parameter function to a function that returns a new tensor map, and updates the implementation to load data via TorchScript.

Changes:

  • Changed load_tensors signature to return std::map<std::string, torch::Tensor> instead of mutating an input map.
  • Reimplemented load_tensors to call torch::jit::load and populate the map from module parameters/buffers.
  • Added the TorchScript header include needed for torch::jit::load.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/utils/serialize.hpp Updates the load_tensors function declaration to return a tensor map.
src/utils/serialize.cpp Updates load_tensors implementation to use TorchScript loading and return a populated map.

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

Comment on lines +33 to +41
/*torch::serialize::InputArchive archive;
archive.load_from(filename);
for (auto& pair : tensor_map) {
for (auto& pair : data) {
try {
archive.read(pair.first, pair.second);
} catch (const c10::Error& e) {
// skip missing tensors
}
}
}*/
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The large commented-out InputArchive block should be removed or re-enabled behind a clear conditional/compile-time flag. Leaving dead code in production makes the intended behavior ambiguous and increases maintenance cost.

Copilot uses AI. Check for mistakes.

void load_tensors(std::map<std::string, torch::Tensor>& tensor_map,
const std::string& filename);
std::map<std::string, torch::Tensor> load_tensors(const std::string& filename);
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The load_tensors API now returns a new map, but the implementation currently only extracts TorchScript module parameters/buffers rather than loading the tensors written by save_tensors. If this is meant to load diagnostic .pt files created by save_tensors, the declaration/semantics should match that format (or the function name/docs should be updated to reflect the TorchScript-only behavior).

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +31
std::map<std::string, torch::Tensor> load_tensors(const std::string& filename) {
std::map<std::string, torch::Tensor> data;

// get keys
torch::jit::Module m = torch::jit::load(filename);

for (const auto& p : m.named_parameters(/*recurse=*/true)) {
data[p.name] = p.value;
}

for (const auto& p : m.named_buffers(/*recurse=*/true)) {
data[p.name] = p.value;
}
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

load_tensors now calls torch::jit::load and returns named_parameters/named_buffers, but save_tensors writes a torch::serialize::OutputArchive. These serialization formats are not compatible, so load_tensors will fail (or silently return unrelated data) when given files produced by save_tensors. Consider either (a) switching load_tensors back to torch::serialize::InputArchive to read the same keys that were written, or (b) updating save_tensors to write a TorchScript Module (register tensors as buffers/parameters) if TorchScript loading is the new intended format.

Copilot uses AI. Check for mistakes.
@chengcli chengcli merged commit 58944ab into main Feb 15, 2026
9 checks passed
@chengcli chengcli deleted the cli/revise_serialize branch February 15, 2026 16:45
@github-actions
Copy link

🎉 Released v1.3.1!

What's Changed

Full Changelog: v1.3.0...v1.3.1

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