Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tensor<T> helper class for tests #7830

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

copybara-service[bot]
Copy link
Contributor

@copybara-service copybara-service bot commented Feb 18, 2025

Add Tensor helper class for tests

This CL does two things: first is adding Tensor<T>, a helper class for multi-dimensional arrays that are frequently used in our tests (but currently are duplicating extent/stride computations and other buffer related logic frequently). Second is modifying a few tests to make some changes:

  • Currently, subgraph tests compare subgraph to operator results. This changes tests to directly check the output, without running the operator code.
  • Currently, subgraph tests run a single random variation, and getting good coverage requires running the test many times. This changes the subgraph tests to test cover many more permutations in a single run.
  • Currently, subgraph tests dig into the internal implementation details of subgraphs (e.g. checking xnn_node_value state). This makes sense in some cases (e.g. fusion tests), but it is both hard to be certain that this covers real usage, and is brittle. IMO, tests should (as much as possible) attempt to verify the behavior is as expected via the APIs that are visible to the user of the thing they are testing. For the subgraph API, that means we should just make sure the subgraph works as expected.
  • Currently subgraph tests are very verbose. IMO this is a problem because it discourages writing tests. This CL adds bfloat16 test coverage for constant_pad (and enables that operation, which previously didn't work for any good reason) with just 3 marginal lines of code, whereas before it would have added several hundred lines of code (copy/paste + modifications)

This change required a few minor cleanups:

  • xnnpack::Buffer<T> needs to be able to distinguish between "extra bytes" and real data.
  • There is now some overlap between RuntimeTester and SubgraphTester. I think we should deprecate RuntimeTester and consolidate everything in SubgraphTester, because we can't return RuntimeTester from the base class SubgraphTester builder methods. This is a minor difficulty, but it also seems like the reason to separate them is minor too.

@copybara-service copybara-service bot changed the title This CL does two things: first is adding Tensor<T>, a helper class for multi-dimensional arrays that are frequently used in our tests (but currently are duplicating extent/stride computations frequently). Second is modifying two tests (slice and transpose) to make some changes: Add Tensor<T> helper class for tests Feb 18, 2025
@copybara-service copybara-service bot force-pushed the test_727983393 branch 8 times, most recently from d25344a to 5f8c80e Compare February 19, 2025 04:33
copybara-service bot pushed a commit that referenced this pull request Feb 19, 2025
…emory

This causes crashes on windows, uncovered in #7830.

PiperOrigin-RevId: 728501674
copybara-service bot pushed a commit that referenced this pull request Feb 19, 2025
…emory

This causes crashes on windows, uncovered in #7830.

This bug appears with `xnn_create_runtime_v4`, other paths that allocate workspaces have matching allocate/free calls.

PiperOrigin-RevId: 728501674
copybara-service bot pushed a commit that referenced this pull request Feb 19, 2025
…emory

This causes crashes on windows, uncovered in #7830.

This bug appears with `xnn_create_runtime_v4`, other paths that allocate workspaces have matching allocate/free calls.

PiperOrigin-RevId: 728501674
copybara-service bot pushed a commit that referenced this pull request Feb 19, 2025
…emory

This causes crashes on windows, uncovered in #7830.

This bug appears with `xnn_create_runtime_v4`, other paths that allocate workspaces have matching allocate/free calls.

PiperOrigin-RevId: 728550543
@copybara-service copybara-service bot force-pushed the test_727983393 branch 3 times, most recently from e3acf6c to 417981a Compare February 20, 2025 18:48
This CL does two things: first is adding `Tensor<T>`, a helper class for multi-dimensional arrays that are frequently used in our tests (but currently are duplicating extent/stride computations and other buffer related logic frequently). Second is modifying a few tests to make some changes:
- Currently, subgraph tests compare subgraph to operator results. This changes tests to directly check the output, without running the operator code.
- Currently, subgraph tests run a single random variation, and getting good coverage requires running the test many times. This changes the subgraph tests to test cover many more permutations in a single run.
- Currently, subgraph tests dig into the internal implementation details of subgraphs (e.g. checking xnn_node_value state). This makes sense in some cases (e.g. fusion tests), but it is both hard to be certain that this covers real usage, and is brittle. IMO, tests should (as much as possible) attempt to verify the behavior is as expected via the APIs that are visible to the user of the thing they are testing. For the subgraph API, that means we should just make sure the subgraph works as expected.
- Currently subgraph tests are very verbose. IMO this is a problem because it discourages writing tests. This CL adds bfloat16 test coverage for constant_pad (and enables that operation, which previously didn't work for any good reason) with just 3 marginal lines of code, whereas before it would have added several hundred lines of code (copy/paste + modifications)

This change required a few minor cleanups:
- `xnnpack::Buffer<T>` needs to be able to distinguish between "extra bytes" and real data.
- There is now some overlap between `RuntimeTester` and `SubgraphTester`. I think we should deprecate `RuntimeTester` and consolidate everything in `SubgraphTester`, because we can't return `RuntimeTester` from the base class `SubgraphTester` builder methods. This is a minor difficulty, but it also seems like the reason to separate them is minor too.

PiperOrigin-RevId: 727983393
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.

1 participant