Skip to content

Instantly share code, notes, and snippets.

@eddiebergman
Last active June 16, 2025 18:54
Show Gist options
  • Save eddiebergman/1e11de0ddf2c78957109b9fec0cd540c to your computer and use it in GitHub Desktop.
Save eddiebergman/1e11de0ddf2c78957109b9fec0cd540c to your computer and use it in GitHub Desktop.
Compiling `pytorch` for debug
git clone [email protected]:pytorch/pytorch.git
cd pytorch
uv venv -p 3.13
source .venv/bin/activate
uv pip install pyyaml setuptools pip
brew install cmake ninja ccache # ccache was recommended on first compile
python setup.py develop
# wait like 10 minutes (M4 Pro, all CPUS burning)
@eddiebergman
Copy link
Author

eddiebergman commented Jun 16, 2025

Also some more found out later: https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#make-no-op-build-fast

DEBUG=1 USE_DISTRIBUTED=0 USE_MKLDNN=0 USE_CUDA=0 BUILD_TEST=0 USE_FBGEMM=0 USE_NNPACK=0 USE_QNNPACK=0 USE_XNNPACK=0 python setup.py develop

@eddiebergman
Copy link
Author

And in lldb

lldb -- python -c "import torch; print(torch.sort(torch.randint(-50, 50, (512,), device='mps', dtype=torch.int64)))"
(lldb) breakpoint set --file Sort.mm --line 20
Breakpoint 2: where = libtorch_cpu.dylib`at::native::structured_sort_stable_out_mps::impl(at::Tensor const&, std::__1::optional<bool>, long long, bool, at::Tensor const&, at::Tensor const&) + 64 at Sort.mm:29:25, address = 0x000000032ec9a320
(lldb) run
Process 43489 launched: '/Users/eddiebergman/code/pytorch/.venv/bin/python' (arm64)
Process 43489 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
    frame #0: 0x00000003089fe320 libtorch_cpu.dylib`at::native::structured_sort_stable_out_mps::impl(this=0x000000016fdfc970, self=0x000000016fdfde30, stable= Has Value=true , dim=-1, descending=false, values=0x000000016fdfc978, indices=0x000000016fdfc980) at Sort.mm:29:25
   26    const Tensor& indices) {
   27     using namespace mps;
   28
-> 29     bool macOS13_3_plus = is_macos_13_or_newer(MacOSVersion::MACOS_VER_13_3_PLUS);
   30     MPS_CHECK_INT64_OP_SUPPORTED(self, macOS13_3_plus, "sort_stable_out");
   31
   32     if (self.numel() == 0) {
Target 0: (python) stopped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment