Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions test/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ def copy_structure_and_params(m):

# crack open the zip format to get at the main module code
archive = zipfile.ZipFile(buffer)
# check that we have no duplicate names
self.assertEqual(len(set(archive.namelist())), len(archive.namelist()))
main_module = archive.open('archive/code/archive.py')
main_module_code = ""
for line in main_module:
Expand Down
6 changes: 6 additions & 0 deletions torch/csrc/jit/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,16 @@ void ScriptModuleSerializer::writeLibs(torch::ModelDef* model_def) {

// Write out the files. We still have to do this in converted_classes_ order,
// to maintain dependency order.
std::unordered_set<std::string> written_files;
for (const auto& item : converted_classes_) {
const ClassTypePtr& class_type = item.key();
const std::string filename =
ImportExportHelpers::qualifierToPath(class_type->qualifier());
if (written_files.count(filename)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would it be trying to write out the same class_type multiple times in the first place?

Copy link
Member Author

Choose a reason for hiding this comment

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

Multiple class types can resolve to the same file.

continue;
}
written_files.insert(filename);

const std::string& src = fileToSrc.at(filename).str();

std::ostringstream lib_stream;
Expand Down