mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: As pointed out in https://github.com/pytorch/pytorch/pull/107479, using a set prevents collisions like "a" => "a", "a" => "a_1", "a_1" => "a_1" (but should go to "a_1_1"). We can combine using counters and a set to avoid this problem. Still gets us the performance benefit in the case of collisions with a very minor penalty in a case with no collision. Test Plan: Extract this code and run: ``` # New version from typing import Dict, Set class Net: _net_names_used_counters: Dict[str, int] = {} _net_names_used: Set[str] = set() staticmethod def current_prefix(): return "test_prefix" staticmethod def _get_next_net_name(basename): basename = "/".join(x for x in [Net.current_prefix(), basename] if x) idx = Net._net_names_used_counters.get(basename, 0) while (name := basename if idx == 0 else f"{basename}_{idx}") in Net._net_names_used: idx += 1 Net._net_names_used_counters[basename] = idx + 1 Net._net_names_used.add(name) return name print(Net._get_next_net_name("basename")) print(Net._get_next_net_name("x_basename")) print(Net._get_next_net_name("basename")) print(Net._get_next_net_name("basename")) print(Net._get_next_net_name("x_basename")) print(Net._get_next_net_name("basename_1")) > test_prefix/basename > test_prefix/x_basename > test_prefix/basename_1 > test_prefix/basename_2 > test_prefix/x_basename_1 > test_prefix/basename_1_1 ``` Differential Revision: D48576516 Pull Request resolved: https://github.com/pytorch/pytorch/pull/107743 Approved by: https://github.com/zdevito |
||
|---|---|---|
| .. | ||
| contrib | ||
| core | ||
| cuda_rtc | ||
| db | ||
| distributed | ||
| experiments | ||
| ideep | ||
| image | ||
| mobile | ||
| mpi | ||
| observers | ||
| onnx | ||
| operators | ||
| opt | ||
| perfkernels | ||
| predictor | ||
| proto | ||
| python | ||
| quantization | ||
| queue | ||
| serialize | ||
| sgd | ||
| share | ||
| test | ||
| transforms | ||
| utils | ||
| video | ||
| __init__.py | ||
| .clang-format | ||
| BUILD_MODE.bzl | ||
| CMakeLists.txt | ||
| README.md | ||
| release-notes.md | ||
| requirements.txt | ||
| unexported_symbols.lds | ||
| VERSION_NUMBER | ||
| version_script.lds | ||
Caffe2
Caffe2 is a lightweight, modular, and scalable deep learning framework. Building on the original Caffe, Caffe2 is designed with expression, speed, and modularity in mind.
Questions and Feedback
Please use GitHub issues (https://github.com/pytorch/pytorch/issues) to ask questions, report bugs, and request new features.