Code tracing for PyTorch models
Project description
torch-code-tracing
Code trace your PyTorch model to understand its exexution and intermediate tensor shapes.
Install
pip install git+https://github.com/justinchuby/torch-code-tracing.git
Usage
from torch_code_tracing import TracingMode
with TracingMode(succinct=True, color=True):
out = model(*args, **kwargs)
out = model(**example_kwargs) # test.py:41 in <module>:
│ ⬇️
│ output = func(self, *args, **kwargs) # site-packages/transformers/utils/generic.py:969 in wrapper:
│ │ ⬇️
│ │ inputs_embeds = self.get_input_embeddings()(llm_input_ids) # site-packages/transformers/models/gemma3/modeling_gemma3.py:1175 in forward:
│ │ │ ⬇️
│ │ │ return super().forward(input_ids) * self.embed_scale.to(self.weight.dtype) # site-packages/transformers/models/gemma3/modeling_gemma3.py:144 in forward:
│ │ │ │ # embedding(bf16[262208, 2560], i64[2, 3], 0) -> bf16[2, 3, 2560];
│ │ │ return super().forward(input_ids) * self.embed_scale.to(self.weight.dtype) # site-packages/transformers/models/gemma3/modeling_gemma3.py:144 in forward:
│ │ │ │ # mul.Tensor(bf16[2, 3, 2560], bf16[]) -> bf16[2, 3, 2560];
│ │ cache_position = torch.arange( # site-packages/transformers/models/gemma3/modeling_gemma3.py:1179 in forward:
│ │ │ # arange.start(30, 33, device=meta, pin_memory=False) -> i64[3];
│ │ causal_mask = self._update_causal_mask( # site-packages/transformers/models/gemma3/modeling_gemma3.py:1205 in forward:
│ │ │ ⬇️
│ │ │ causal_mask = torch.full( # site-packages/transformers/models/gemma3/modeling_gemma3.py:1050 in _update_causal_mask:
│ │ │ │ # full([3, 33], -3.3895313892515355e+38, dtype=torch.bfloat16, device=meta, pin_memory=False) -> bf16[3, 33];
│ │ │ causal_mask = torch.triu(causal_mask, diagonal=1) # site-packages/transformers/models/gemma3/modeling_gemma3.py:1056 in _update_causal_mask:
│ │ │ │ # triu(bf16[3, 33], 1) -> bf16[3, 33];
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch_code_tracing-0.1.1.tar.gz.
File metadata
- Download URL: torch_code_tracing-0.1.1.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78e43c65e923ea916e6c75c21bff84902eca85aee9977155e77a39560118de2b
|
|
| MD5 |
b902dbade54b65cd22a0f1642199622f
|
|
| BLAKE2b-256 |
4524d8e273ab4daffa9ce8d6c10b49ea2793c495eea99f1661902f037ce8e4bf
|
Provenance
The following attestation bundles were made for torch_code_tracing-0.1.1.tar.gz:
Publisher:
main.yml on justinchuby/torch-code-tracing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_code_tracing-0.1.1.tar.gz -
Subject digest:
78e43c65e923ea916e6c75c21bff84902eca85aee9977155e77a39560118de2b - Sigstore transparency entry: 552971928
- Sigstore integration time:
-
Permalink:
justinchuby/torch-code-tracing@010afc0afc5e69c4f3d7333d742ba5d5aa065db3 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/justinchuby
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@010afc0afc5e69c4f3d7333d742ba5d5aa065db3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torch_code_tracing-0.1.1-py3-none-any.whl.
File metadata
- Download URL: torch_code_tracing-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
703066ba639e6f463af9e5da9bc9f6a019d1709a076b27e51b670a1b7c2f380b
|
|
| MD5 |
c183987c14cad538e11cc846ed4427f9
|
|
| BLAKE2b-256 |
74d1a6e59a6e760d867dbc6266a5d0a41a14d16eccca1382db4507f608d0df82
|
Provenance
The following attestation bundles were made for torch_code_tracing-0.1.1-py3-none-any.whl:
Publisher:
main.yml on justinchuby/torch-code-tracing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_code_tracing-0.1.1-py3-none-any.whl -
Subject digest:
703066ba639e6f463af9e5da9bc9f6a019d1709a076b27e51b670a1b7c2f380b - Sigstore transparency entry: 552971944
- Sigstore integration time:
-
Permalink:
justinchuby/torch-code-tracing@010afc0afc5e69c4f3d7333d742ba5d5aa065db3 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/justinchuby
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@010afc0afc5e69c4f3d7333d742ba5d5aa065db3 -
Trigger Event:
push
-
Statement type: