Skip to content

Tensorbored torch import issue#63

Merged
Demonstrandum merged 6 commits into
masterfrom
cursor/tensorbored-torch-import-issue-ca77
Mar 2, 2026
Merged

Tensorbored torch import issue#63
Demonstrandum merged 6 commits into
masterfrom
cursor/tensorbored-torch-import-issue-ca77

Conversation

@Demonstrandum

Copy link
Copy Markdown
Owner

Motivation for features / changes

This PR addresses two key issues:

  1. tensorbored.torch.SummaryWriter was not importable from the PyPI package. The torch.py file, which provides the SummaryWriter integration, was missing from the published wheel, preventing users from following the README's suggested usage.
  2. The demo script (demo/generate_demo_data.py) was overly complex and misleading. It used low-level protobuf APIs to write events, rather than showcasing the intended high-level SummaryWriter API. This made the demo a poor example of basic library usage.

Technical description of changes

  1. Include torch.py in the pip package:
    • Added a py_library target for torch.py in tensorbored/BUILD.
    • Added this new target as a dependency to the build_pip_package rule in tensorbored/pip_package/BUILD.
    • Added [tool.setuptools.packages.find] configuration to pyproject.toml to ensure correct package discovery during local builds.
  2. Simplify demo/generate_demo_data.py:
    • Rewrote the demo to use from tensorbored.torch import SummaryWriter and its add_scalar, add_histogram, add_image, and add_text methods.
    • Removed approximately 80 lines of manual protobuf construction and helper functions, significantly reducing complexity and improving readability.

Screenshots of UI changes (or N/A)

N/A

Detailed steps to verify changes work correctly (as executed by you)

  1. Ensure PyTorch is installed: pip install torch.
  2. Build the package locally from the repository root: python -m build.
  3. Install the generated wheel file (e.g., pip install dist/tensorbored-*-py3-none-any.whl).
  4. Verify tensorbored.torch.SummaryWriter is importable:
    python -c "from tensorbored.torch import SummaryWriter; print(SummaryWriter)"
    This should print the class object without error.
  5. Run the updated demo script: python demo/generate_demo_data.py.
  6. Verify the script runs to completion without errors and generates event files in the runs/ directory.

Alternate designs / implementations considered (or N/A)

N/A


Open in Web Open in Cursor 

cursoragent and others added 2 commits March 2, 2026 14:46
torch.py was missing from the built wheel because:

1. It had no Bazel py_library target in tensorbored/BUILD, so the
   Bazel-based build_pip_package never copied it into the wheel.

2. pyproject.toml lacked a [tool.setuptools.packages.find] directive,
   causing setuptools flat-layout auto-discovery to fail when building
   directly from the repo root.

Add the 'torch' Bazel target, wire it into pip_package/BUILD data deps,
and pin setuptools package discovery to 'tensorbored*'.

Co-authored-by: Samuel <samuel@knutsen.co>
The demo is supposed to represent basic library usage, but was using
low-level internals (event_pb2, summary_pb2, TensorProto,
EventFileWriter) to construct and write summaries by hand.

Replace all of that with the recommended user-facing API:

    from tensorbored.torch import SummaryWriter
    writer = SummaryWriter(log_dir=...)
    writer.add_scalar(...)
    writer.add_histogram(...)
    writer.add_image(..., dataformats='HWC')
    writer.add_text(...)

This removes ~80 lines of boilerplate (make_scalar_summary,
make_image_summary, make_histogram_summary, make_text_summary,
add_summary) and makes the demo match the README's recommended usage.

Co-authored-by: Samuel <samuel@knutsen.co>
@cursor

cursor Bot commented Mar 2, 2026

Copy link
Copy Markdown

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@github-actions

github-actions Bot commented Mar 2, 2026

Copy link
Copy Markdown

Preview Deployment

Status ✅ Running
Live Preview https://Demonstrandum-tensorbored-pr-63.hf.space
Space https://huggingface.co/spaces/Demonstrandum/tensorbored-pr-63
Details
  • Wheel: tensorbored_nightly-2.21.0a20260302-py3-none-any.whl
  • Commit: 65ab440
  • Build status: success

cursoragent and others added 4 commits March 2, 2026 15:02
Without __main__.py in the wheel, running 'python -m tensorbored'
fails with:

    No module named tensorbored.__main__; 'tensorbored' is a package
    and cannot be directly executed

Add a Bazel py_library target and wire it into the pip package build.

Co-authored-by: Samuel <samuel@knutsen.co>
Co-authored-by: Samuel <samuel@knutsen.co>
Co-authored-by: Samuel <samuel@knutsen.co>
The demo now uses 'from tensorbored.torch import SummaryWriter' which
requires torch. Add the CPU-only wheel to keep the image small.

Co-authored-by: Samuel <samuel@knutsen.co>
@Demonstrandum Demonstrandum marked this pull request as ready for review March 2, 2026 16:42
@Demonstrandum Demonstrandum merged commit 7e215f1 into master Mar 2, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants