Last active
July 10, 2025 18:55
-
-
Save ngoldbaum/6d892723014aed05096df9a98b2a2cf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| libc++abi: terminating due to uncaught exception of type c10::Error: !storage_impl->pyobj_slot()->owns_pyobj() INTERNAL ASSERT FAILED at "/Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/Storage.cpp":195, please report a bug to PyTorch. | |
| Exception raised from THPStorage_tryPreserve at /Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/Storage.cpp:195 (most recent call first): | |
| frame #0: c10::Error::Error(c10::SourceLocation, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>) + 56 (0x10071d0f8 in libc10.dylib) | |
| frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, char const*) + 192 (0x10071a0dc in libc10.dylib) | |
| frame #2: torch::autograd::maybe_warn_requires_grad(at::Tensor const&)::$_0::operator()() const + 0 (0x102ed7f70 in libtorch_python.dylib) | |
| frame #3: THPStorage_subclass_dealloc(_object*) + 1212 (0x1032000f8 in libtorch_python.dylib) | |
| <omitting python frames> | |
| frame #8: _pthread_start + 136 (0x195feac0c in libsystem_pthread.dylib) | |
| frame #9: thread_start + 8 (0x195fe5b80 in libsystem_pthread.dylib) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (lldb) r | |
| Process 36722 launched: '/Users/goldbaum/.pyenv/versions/3.13.4t/bin/python' (arm64) | |
| Process 36722 stopped | |
| * thread #3, stop reason = EXC_BAD_ACCESS (code=1, address=0x3d) | |
| frame #0: 0x0000000102c7e6bc libtorch_python.dylib`THPStorage_dataPtr(_object*, _object*) + 72 | |
| libtorch_python.dylib`THPStorage_dataPtr: | |
| -> 0x102c7e6bc <+72>: ldrb w8, [x19, #0x3d] | |
| 0x102c7e6c0 <+76>: cbnz w8, 0x102c7e834 ; <+448> | |
| 0x102c7e6c4 <+80>: ldr x8, [x19, #0x10] | |
| 0x102c7e6c8 <+84>: cbnz x8, 0x102c7e76c ; <+248> | |
| thread #4, stop reason = EXC_BAD_ACCESS (code=1, address=0x3d) | |
| frame #0: 0x0000000102c7e6bc libtorch_python.dylib`THPStorage_dataPtr(_object*, _object*) + 72 | |
| libtorch_python.dylib`THPStorage_dataPtr: | |
| -> 0x102c7e6bc <+72>: ldrb w8, [x19, #0x3d] | |
| 0x102c7e6c0 <+76>: cbnz w8, 0x102c7e834 ; <+448> | |
| 0x102c7e6c4 <+80>: ldr x8, [x19, #0x10] | |
| 0x102c7e6c8 <+84>: cbnz x8, 0x102c7e76c ; <+248> | |
| thread #5, stop reason = EXC_BAD_ACCESS (code=1, address=0x3d) | |
| frame #0: 0x0000000102c7e6bc libtorch_python.dylib`THPStorage_dataPtr(_object*, _object*) + 72 | |
| libtorch_python.dylib`THPStorage_dataPtr: | |
| -> 0x102c7e6bc <+72>: ldrb w8, [x19, #0x3d] | |
| 0x102c7e6c0 <+76>: cbnz w8, 0x102c7e834 ; <+448> | |
| 0x102c7e6c4 <+80>: ldr x8, [x19, #0x10] | |
| 0x102c7e6c8 <+84>: cbnz x8, 0x102c7e76c ; <+248> | |
| Target 0: (python) stopped. | |
| (lldb) bt all | |
| thread #1, queue = 'com.apple.main-thread' | |
| frame #0: 0x0000000195fac3cc libsystem_kernel.dylib`__psynch_cvwait + 8 | |
| frame #1: 0x0000000195feb0e0 libsystem_pthread.dylib`_pthread_cond_wait + 984 | |
| frame #2: 0x00000001008b1af0 libpython3.13t.dylib`_PySemaphore_Wait + 248 | |
| frame #3: 0x00000001008b1ce8 libpython3.13t.dylib`_PyParkingLot_Park + 420 | |
| frame #4: 0x00000001008aab34 libpython3.13t.dylib`PyEvent_WaitTimed + 108 | |
| frame #5: 0x00000001009401f0 libpython3.13t.dylib`ThreadHandle_join + 428 | |
| frame #6: 0x000000010094080c libpython3.13t.dylib`PyThreadHandleObject_join + 120 | |
| frame #7: 0x000000010071ebec libpython3.13t.dylib`method_vectorcall_VARARGS + 144 | |
| frame #8: 0x00000001007114f0 libpython3.13t.dylib`PyObject_Vectorcall + 88 | |
| frame #9: 0x0000000100855494 libpython3.13t.dylib`_PyEval_EvalFrameDefault + 36992 | |
| frame #10: 0x000000010084c168 libpython3.13t.dylib`PyEval_EvalCode + 368 | |
| frame #11: 0x00000001008c2184 libpython3.13t.dylib`run_eval_code_obj + 180 | |
| frame #12: 0x00000001008c1c1c libpython3.13t.dylib`run_mod + 220 | |
| frame #13: 0x00000001008be8f0 libpython3.13t.dylib`_PyRun_SimpleFileObject + 912 | |
| frame #14: 0x00000001008be1b8 libpython3.13t.dylib`_PyRun_AnyFileObject + 160 | |
| frame #15: 0x00000001008e5ac8 libpython3.13t.dylib`pymain_run_file + 332 | |
| frame #16: 0x00000001008e5168 libpython3.13t.dylib`Py_RunMain + 1988 | |
| frame #17: 0x00000001008e541c libpython3.13t.dylib`pymain_main + 324 | |
| frame #18: 0x00000001008e54bc libpython3.13t.dylib`Py_BytesMain + 40 | |
| frame #19: 0x0000000195c4ab98 dyld`start + 6076 | |
| thread #2 | |
| frame #0: 0x0000000100884df8 libpython3.13t.dylib`_PyFrame_ClearLocals + 84 | |
| frame #1: 0x0000000100885028 libpython3.13t.dylib`_PyFrame_ClearExceptCode + 428 | |
| frame #2: 0x000000010085977c libpython3.13t.dylib`_PyEval_FrameClearAndPop + 148 | |
| frame #3: 0x0000000100850344 libpython3.13t.dylib`_PyEval_EvalFrameDefault + 16176 | |
| frame #4: 0x0000000100711f68 libpython3.13t.dylib`_PyObject_CallFunctionVa + 160 | |
| frame #5: 0x0000000100711ebc libpython3.13t.dylib`PyObject_CallFunction + 56 | |
| frame #6: 0x000000010090dc4c libpython3.13t.dylib`_io_FileIO___init__ + 1392 | |
| frame #7: 0x00000001007abf80 libpython3.13t.dylib`type_call + 448 | |
| frame #8: 0x0000000100710d50 libpython3.13t.dylib`_PyObject_MakeTpCall + 324 | |
| frame #9: 0x00000001007120c4 libpython3.13t.dylib`_PyObject_CallFunctionVa + 508 | |
| frame #10: 0x0000000100711ebc libpython3.13t.dylib`PyObject_CallFunction + 56 | |
| frame #11: 0x000000010090a97c libpython3.13t.dylib`_io_open + 1684 | |
| frame #12: 0x00000001007755c4 libpython3.13t.dylib`cfunction_vectorcall_FASTCALL_KEYWORDS + 168 | |
| frame #13: 0x00000001007114f0 libpython3.13t.dylib`PyObject_Vectorcall + 88 | |
| frame #14: 0x0000000100855224 libpython3.13t.dylib`_PyEval_EvalFrameDefault + 36368 | |
| frame #15: 0x0000000100714358 libpython3.13t.dylib`method_vectorcall + 316 | |
| frame #16: 0x000000010093fa10 libpython3.13t.dylib`thread_run + 128 | |
| frame #17: 0x00000001008d5c9c libpython3.13t.dylib`pythread_wrapper + 28 | |
| frame #18: 0x0000000195feac0c libsystem_pthread.dylib`_pthread_start + 136 | |
| * thread #3, stop reason = EXC_BAD_ACCESS (code=1, address=0x3d) | |
| * frame #0: 0x0000000102c7e6bc libtorch_python.dylib`THPStorage_dataPtr(_object*, _object*) + 72 | |
| frame #1: 0x000000010071f0b0 libpython3.13t.dylib`method_vectorcall_NOARGS + 140 | |
| frame #2: 0x00000001007114f0 libpython3.13t.dylib`PyObject_Vectorcall + 88 | |
| frame #3: 0x0000000100855494 libpython3.13t.dylib`_PyEval_EvalFrameDefault + 36992 | |
| frame #4: 0x0000000100714358 libpython3.13t.dylib`method_vectorcall + 316 | |
| frame #5: 0x000000010093fa10 libpython3.13t.dylib`thread_run + 128 | |
| frame #6: 0x00000001008d5c9c libpython3.13t.dylib`pythread_wrapper + 28 | |
| frame #7: 0x0000000195feac0c libsystem_pthread.dylib`_pthread_start + 136 | |
| thread #4, stop reason = EXC_BAD_ACCESS (code=1, address=0x3d) | |
| frame #0: 0x0000000102c7e6bc libtorch_python.dylib`THPStorage_dataPtr(_object*, _object*) + 72 | |
| frame #1: 0x000000010071f0b0 libpython3.13t.dylib`method_vectorcall_NOARGS + 140 | |
| frame #2: 0x00000001007114f0 libpython3.13t.dylib`PyObject_Vectorcall + 88 | |
| frame #3: 0x0000000100855494 libpython3.13t.dylib`_PyEval_EvalFrameDefault + 36992 | |
| frame #4: 0x0000000100714358 libpython3.13t.dylib`method_vectorcall + 316 | |
| frame #5: 0x000000010093fa10 libpython3.13t.dylib`thread_run + 128 | |
| frame #6: 0x00000001008d5c9c libpython3.13t.dylib`pythread_wrapper + 28 | |
| frame #7: 0x0000000195feac0c libsystem_pthread.dylib`_pthread_start + 136 | |
| thread #5, stop reason = EXC_BAD_ACCESS (code=1, address=0x3d) | |
| frame #0: 0x0000000102c7e6bc libtorch_python.dylib`THPStorage_dataPtr(_object*, _object*) + 72 | |
| frame #1: 0x000000010071f0b0 libpython3.13t.dylib`method_vectorcall_NOARGS + 140 | |
| frame #2: 0x00000001007114f0 libpython3.13t.dylib`PyObject_Vectorcall + 88 | |
| frame #3: 0x0000000100855494 libpython3.13t.dylib`_PyEval_EvalFrameDefault + 36992 | |
| frame #4: 0x0000000100714358 libpython3.13t.dylib`method_vectorcall + 316 | |
| frame #5: 0x000000010093fa10 libpython3.13t.dylib`thread_run + 128 | |
| frame #6: 0x00000001008d5c9c libpython3.13t.dylib`pythread_wrapper + 28 | |
| frame #7: 0x0000000195feac0c libsystem_pthread.dylib`_pthread_start + 136 | |
| thread #6 | |
| frame #0: 0x0000000195f1c3fc libc++.1.dylib`std::__1::mutex::lock() | |
| frame #1: 0x000000011528c6a8 libtorch_cpu.dylib`torch::autograd::AutogradMeta::fw_grad(unsigned long long, at::TensorBase const&) const + 100 | |
| frame #2: 0x00000001146f84c4 libtorch_cpu.dylib`c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor& (c10::DispatchKeySet, at::Tensor&, at::Tensor const&, c10::Scalar const&), &torch::autograd::VariableType::(anonymous namespace)::add__Tensor(c10::DispatchKeySet, at::Tensor&, at::Tensor const&, c10::Scalar const&)>, at::Tensor&, c10::guts::typelist::typelist<c10::DispatchKeySet, at::Tensor&, at::Tensor const&, c10::Scalar const&>>, at::Tensor& (c10::DispatchKeySet, at::Tensor&, at::Tensor const&, c10::Scalar const&)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor&, at::Tensor const&, c10::Scalar const&) + 248 | |
| frame #3: 0x0000000111da4e48 libtorch_cpu.dylib`at::_ops::add__Tensor::call(at::Tensor&, at::Tensor const&, c10::Scalar const&) + 304 | |
| frame #4: 0x00000001028b5e80 libtorch_python.dylib`torch::autograd::THPVariable_add_(_object*, _object*, _object*) + 1196 | |
| frame #5: 0x000000010289d418 libtorch_python.dylib`_object* torch::autograd::TypeError_to_NotImplemented_<&torch::autograd::THPVariable_add_(_object*, _object*, _object*)>(_object*, _object*, _object*) + 12 | |
| frame #6: 0x000000010071edcc libpython3.13t.dylib`method_vectorcall_VARARGS_KEYWORDS + 244 | |
| frame #7: 0x00000001007b1670 libpython3.13t.dylib`vectorcall_method + 144 | |
| frame #8: 0x00000001007b8a78 libpython3.13t.dylib`slot_nb_inplace_add + 60 | |
| frame #9: 0x00000001006f4fbc libpython3.13t.dylib`PyNumber_InPlaceAdd + 68 | |
| frame #10: 0x0000000100850224 libpython3.13t.dylib`_PyEval_EvalFrameDefault + 15888 | |
| frame #11: 0x0000000100714358 libpython3.13t.dylib`method_vectorcall + 316 | |
| frame #12: 0x000000010093fa10 libpython3.13t.dylib`thread_run + 128 | |
| frame #13: 0x00000001008d5c9c libpython3.13t.dylib`pythread_wrapper + 28 | |
| frame #14: 0x0000000195feac0c libsystem_pthread.dylib`_pthread_start + 136 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tempfile | |
| import threading | |
| import torch | |
| from safetensors.torch import save_file, load_file | |
| b = threading.Barrier(5) | |
| done = 0 | |
| def save_worker(tensors_to_save): | |
| b.wait() | |
| try: | |
| with tempfile.NamedTemporaryFile() as fp: | |
| save_file(tensors_to_save, fp.name) | |
| loaded_tensors = load_file(fp.name) | |
| for name, tensor in tensors_to_save.items(): | |
| if name == '4': | |
| continue | |
| assert torch.equal(loaded_tensors[name], tensor), (loaded_tensors[name], tensor) | |
| finally: | |
| global done | |
| done += 1 | |
| def mutate_tensor(tensors): | |
| b.wait() | |
| while done < 4: | |
| tensors['4'] += 1 | |
| if __name__ == "__main__": | |
| tensors_to_save = { | |
| '1': torch.randn(100, 768), | |
| '2': torch.randn(2304, 768), | |
| '3': torch.zeros(5000), | |
| '4': torch.tensor(5000.), # Example of a scalar tensor | |
| '5': torch.tensor(768, dtype=torch.int32), # Example of an integer tensor | |
| } | |
| filename = "my_tensors.safetensors" | |
| tasks = [threading.Thread(target=save_worker, args=(tensors_to_save,)) for _ in range(4)] | |
| tasks.append(threading.Thread(target=mutate_tensor, args=(tensors_to_save,))) | |
| [t.start() for t in tasks] | |
| [t.join() for t in tasks] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment