DSO boundaries fails for template specialisations whose typeinfo ++ // symbol is HIDDEN (not exported). Use kind() + static_cast instead. ++ if (base->kind() != T::kAttrKind) { ++ throw IRAttributeError(name, true); ++ } ++ return static_cast(base)->value(); ++#else ++ auto* child = dynamic_cast(base); + if (child == nullptr) { + throw IRAttributeError(name, true); + } + return child->value(); ++#endif + } + using AVPtr = AttributeValue::Ptr; + // NB: For determinism, we use a vector rather than a hash map. This does diff --git a/misc/py-pytorch/files/patch-torch_csrc_jit_passes_inplace__check.cpp b/misc/py-pytorch/files/patch-torch_csrc_jit_passes_inplace__check.cpp new file mode 100644 index 000000000000..cd2b0094b85d --- /dev/null +++ b/misc/py-pytorch/files/patch-torch_csrc_jit_passes_inplace__check.cpp @@ -0,0 +1,21 @@ +--- torch/csrc/jit/passes/inplace_check.cpp.orig 2026-04-18 04:20:00 UTC ++++ torch/csrc/jit/passes/inplace_check.cpp +@@ -7,8 +7,17 @@ static void CheckInplace(Block* block) { + static void CheckInplace(Block* block) { + for (auto node : block->nodes()) { + if (node->kind() == prim::PythonOp && node->hasAttribute(attr::inplace)) { ++ // On FreeBSD, ScalarAttributeValue typeinfo symbols are local to each ++ // DSO (no exported key function), so dynamic_cast across DSO boundaries ++ // (from python to cpu library) may fail. Guard with try/catch. ++ bool is_inplace = false; ++ try { ++ is_inplace = (bool)node->i(attr::inplace); ++ } catch (const std::exception&) { ++ // Cannot determine; treat as not-inplace (conservative safe default). ++ } + TORCH_CHECK( +- !node->i(attr::inplace), ++ !is_inplace, + "inplace ", + static_cast(node)->name(), + " not supported in the JIT"); diff --git a/misc/py-pytorch/files/patch-torch_distributed_elastic_multiprocessing_redirects.py b/misc/py-pytorch/files/patch-torch_distributed_elastic_multiprocessing_redirects.py new file mode 100644 index 000000000000..7982c51cfd73 --- /dev/null +++ b/misc/py-pytorch/files/patch-torch_distributed_elastic_multiprocessing_redirects.py @@ -0,0 +1,13 @@ +--- torch/distributed/elastic/multiprocessing/redirects.py.orig 2026-04-19 02:32:30 UTC ++++ torch/distributed/elastic/multiprocessing/redirects.py +@@ -31,7 +31,9 @@ def get_libc(): + ) + return None + else: +- return ctypes.CDLL("libc.so.6") ++ import ctypes.util ++ libc_name = ctypes.util.find_library("c") or "libc.so.6" ++ return ctypes.CDLL(libc_name) + + + libc = get_libc() diff --git a/misc/py-pytorch/files/patch-torch_jit___trace.py b/misc/py-pytorch/files/patch-torch_jit___trace.py index 5415c1466564..a34e198af2a1 100644 --- a/misc/py-pytorch/files/patch-torch_jit___trace.py +++ b/misc/py-pytorch/files/patch-torch_jit___trace.py @@ -1,6 +1,59 @@ --- torch/jit/_trace.py.orig 2026-04-18 00:49:58 UTC +++ torch/jit/_trace.py -@@ -445,8 +445,11 @@ def _check_trace( +@@ -300,6 +300,13 @@ def indent(s): + return "\n".join(["\t" + line for line in s.splitlines()]) + + ++def _safe_str(x): ++ try: ++ return str(x) ++ except RuntimeError: ++ return "" ++ ++ + class TracingCheckError(Exception): + def __init__(self, graph_diff_error, tensor_compare_error, extra_msg=None): + self.message = "Tracing failed sanity checks!\n" +@@ -387,12 +394,18 @@ def _check_trace( + mod_canonicalized = torch._C._jit_pass_canonicalize(traced_func.graph) + torch._C._jit_pass_inline(mod_canonicalized) + torch._C._jit_pass_erase_shape_information(mod_canonicalized) +- mod_str = str(mod_canonicalized) ++ try: ++ mod_str = str(mod_canonicalized) ++ except RuntimeError: ++ mod_str = "" + mod_str = re.sub(r"___torch_mangle_[0-9]+\.", "", mod_str) + check_canonicalized = torch._C._jit_pass_canonicalize(check_mod_func.graph) + torch._C._jit_pass_inline(check_canonicalized) + torch._C._jit_pass_erase_shape_information(check_canonicalized) +- check_str = str(check_canonicalized) ++ try: ++ check_str = str(check_canonicalized) ++ except RuntimeError: ++ check_str = "" + check_str = re.sub(r"___torch_mangle_[0-9]+\.", "", check_str) + + graph_diff_errors = None +@@ -407,10 +420,15 @@ def _check_trace( + for n_mod, n_check in zip( + mod_canonicalized.nodes(), check_canonicalized.nodes() + ): +- if str(n_mod) != str(n_check): ++ try: ++ n_mod_str = str(n_mod) ++ n_check_str = str(n_check) ++ except RuntimeError: *** 109 LINES SKIPPED ***