test(svd): align with Paddle compat svd behavior#67
Open
youge325 wants to merge 9 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a cross-framework SVD test that exercises at::svd and Tensor::svd() over a matrix of shapes, dtypes, and API variants, and records the alignment work in the mismatch-API log. The test relies on the existing glob-based CMake harness, so it will be built as both paddle_SvdTest and torch_SvdTest, with results diffed via test/result_cmp.sh. Because SVD outputs are not bit-stable, the test only serializes tensor metadata (dim, numel, sizes, dtype) rather than numeric values.
Changes:
- New
test/ATen/ops/SvdTest.cppwith 11 test cases covering shape, dtype, and API-variant matrix. - New "对齐迭代记录(2026-05-29)" section in
doc/ATen/ops/mismatch_api_record.mddocumenting compat-layer mapping and validation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/ATen/ops/SvdTest.cpp | New cross-framework SVD test; serializes metadata for U/S/V across shapes, dtypes, and some/compute_uv variants. |
| doc/ATen/ops/mismatch_api_record.md | Adds alignment-iteration record for at::svd / Tensor::svd, listing compat-layer paths, coverage, and validation results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+211
to
+220
| // 验证 U 和 V 都是零 | ||
| float u_sum = U.abs().sum().item().template to<float>(); | ||
| float v_sum = V.abs().sum().item().template to<float>(); | ||
| bool u_all_zero = u_sum == 0.0f; | ||
| bool v_all_zero = v_sum == 0.0f; | ||
| file << std::to_string(u_all_zero) << " "; | ||
| file << std::to_string(v_all_zero) << " "; | ||
| file << "\n"; | ||
| file.saveFile(); | ||
| } |
Comment on lines
+246
to
+254
| float u_sum = U.abs().sum().item().template to<float>(); | ||
| float v_sum = V.abs().sum().item().template to<float>(); | ||
| bool u_all_zero = u_sum == 0.0f; | ||
| bool v_all_zero = v_sum == 0.0f; | ||
| file << std::to_string(u_all_zero) << " "; | ||
| file << std::to_string(v_all_zero) << " "; | ||
| file << "\n"; | ||
| file.saveFile(); | ||
| } |
|
|
||
| ### 2) 测试覆盖 | ||
| - 测试文件:`test/ATen/ops/SvdTest.cpp`(PCAT)、`test/cpp/compat/ATen_svd_test.cc`(Paddle compat) | ||
| - 新增/修改用例:SvdBasic、SmallMatrix、SquareMatrix、WideMatrix、LargeMatrix、BatchMatrix、Float64Dtype、FullMatrices、NoComputeUv、MethodSvd、FullNoComputeUv |
013ef8f to
8bef3b7
Compare
8bef3b7 to
c08598c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add cross-framework comparison tests for
at::svd/Tensor::svdto verify Paddle compat layer behavior matches PyTorch.Test coverage
at::svd(t),t.svd(),svd(t, some=false),svd(t, compute_uv=false)Related: PaddlePaddle/Paddle#79187