mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-05-07 02:03:55 -05:00
[PR #1392] [MERGED] test(tinytorch): PyTorch-compat test coverage for Tensor API additions #8160
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/harvard-edge/cs249r_book/pull/1392
Author: @Shashank-Tripathi-07
Created: 4/17/2026
Status: ✅ Merged
Merged: 4/20/2026
Merged by: @profvjreddi
Base:
dev← Head:feat/tensor-pytorch-compat-api📝 Commits (2)
3b0fd02test(tinytorch): add PyTorch-compat coverage for ndim, numel, view, contiguous, masked_fill4de0f71feat(tinytorch): add view(), masked_fill(), and Tensor stacking to src📊 Changes
2 files changed (+109 additions, -1 deletions)
View changed files
📝
tinytorch/src/01_tensor/01_tensor.py(+24 -1)📝
tinytorch/tests/01_tensor/test_tensor_core.py(+85 -0)📄 Description
Summary
Adds
TestTensorPyTorchCompat, 10 focused tests covering the PyTorch-compatible Tensor methods that landed in #1391 and the subsequent merge window (view, masked_fill, Tensor stacking).Also syncs
src/01_tensor/01_tensor.pywith the exported package:view(),masked_fill(), and Tensor stacking were present incore/tensor.pybut missing from the source file, causing CI failures.Closes #1298.
Why these tests matter: students porting PyTorch training loops to TinyTorch will call these methods constantly. Without explicit coverage, a refactor could silently break the behavioral contracts. The -inf attention-mask pattern in
masked_fillis especially tricky: it produces no exception, just wrong softmax output.Each test targets one specific contract:
test_ndimtest_numeltest_view_same_as_reshapetest_view_with_minus_onetest_contiguous_returns_correct_datatest_contiguous_is_c_contiguoustest_masked_fill_basictest_masked_fill_attention_patterntest_masked_fill_does_not_mutate_originaltest_tensor_from_tensor_listTest plan
pytest tinytorch/tests/01_tensor/test_tensor_core.py::TestTensorPyTorchCompat -vall 10 pass🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.