Skip to main content

Code tracing for PyTorch models

Project description

torch-code-tracing

Code trace your PyTorch model

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_code_tracing-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_code_tracing-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file torch_code_tracing-0.1.0.tar.gz.

File metadata

  • Download URL: torch_code_tracing-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for torch_code_tracing-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dc87a19e5d81759253cd61c5a25aeb78d84ca3c4229eb919d2c3755049f39620
MD5 a067bfc7805a8bb6337f885e8d60878b
BLAKE2b-256 27b1f8501a4a6c93934b42027260d54cb59b7d37a8fbcc0f93a1de74f739a9ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_code_tracing-0.1.0.tar.gz:

Publisher: main.yml on justinchuby/torch-code-tracing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torch_code_tracing-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for torch_code_tracing-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 368073201affd836bed0b3550cb74de37628515b0fe8d7f5fe5d9f9004132b00
MD5 cc9669da58dfde638a7525c84ce71fb1
BLAKE2b-256 4040c7b79bb4f2f5e2b6630b58e374e4babc2b4788464c69c94ce64095a0a1cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_code_tracing-0.1.0-py3-none-any.whl:

Publisher: main.yml on justinchuby/torch-code-tracing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page