Skip to content

Conversation

@jeffkbkim
Copy link
Contributor

@jeffkbkim jeffkbkim commented Jun 25, 2025

Main test lies in test_tensor_weighted_avg.py (format similar to test_weighted_avg.py)

This patch adds a unit test for TensorWeightedAvgMetric.

TensorWeightedAvgMetric allows users to pass in a tensor that is not a prediction/weight/label with a corresponding tensor name, into a dict called "required_inputs". The purpose is to compute and emit the weighted average of a tensor of their choice.

However, the existing framework for the rec metric testing module does not support processing tensors under "required_inputs". Main modifications to other tests include changes to the TestMetric's _get_states() method signature to support processing tensor passed into "required_inputs".

Increases code coverage from 0% to 97.5%

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 25, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77169334

jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Jun 26, 2025
Summary:

Main test lies in test_tensor_weighted_avg.py

This patch adds a unit test for TensorWeightedAvg metric. The existing framework for the rec metric testing module did not support processing tensors tied to a task's tensor_name, which the tensor weighted avg metric uses.

Main modifications to other tests include changes to the TestMetric's _get_states() method signature to support processing arbitrary tensors in the testing framework.

Rollback Plan:

Differential Revision: D77169334
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77169334

jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Jun 26, 2025
Summary:

Main test lies in `test_tensor_weighted_avg.py`

This patch adds a unit test for TensorWeightedAvg metric. The existing framework for the rec metric testing module did not support processing tensors tied to a task's tensor_name, which the tensor weighted avg metric uses.

Increases code coverage to 97.7%. [Previous external tests covered 35%](https://www.internalfb.com/quality/coverage?query=%7B%22key%22%3A%22AND%22%2C%22children%22%3A[%7B%22key%22%3A%22CONTAINS_ANY_OF_FBIDS%22%2C%22field%22%3A%22CODE_QUALITY_ONCALL%22%2C%22value%22%3A[%7B%22title%22%3A%22torchrec%20(torchrec%20%3A%20Zain%20Huda)%22%2C%22fbid%22%3A%22711323163133477%22%2C%22photo%22%3A%22%22%7D]%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Ffb%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22tests%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22__init__.py%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fgithub%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fcsrc%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fdatasets%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Finference%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fpt2%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22benchmark%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fmetrics%2F%22%7D]%7D&is_e2e=false&show_all_partitions=false&split_graph=true)

Main modifications to other tests include changes to the TestMetric's _get_states() method signature to support processing arbitrary tensors in the testing framework.

Differential Revision: D77169334
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77169334

jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Jun 26, 2025
Summary:

Main test lies in `test_tensor_weighted_avg.py` (format similar to `test_weighted_avg.py`)

This patch adds a unit test for TensorWeightedAvgMetric. The existing framework for the rec metric testing module does not support processing tensors tied to a task's tensor_name, which the tensor weighted avg metric uses. Main modifications to other tests include changes to the TestMetric's _get_states() method signature to support processing arbitrary tensors in the testing framework.

Increases code coverage to 97.7%. [Previous external tests covered 35%](https://www.internalfb.com/quality/coverage?query=%7B%22key%22%3A%22AND%22%2C%22children%22%3A[%7B%22key%22%3A%22CONTAINS_ANY_OF_FBIDS%22%2C%22field%22%3A%22CODE_QUALITY_ONCALL%22%2C%22value%22%3A[%7B%22title%22%3A%22torchrec%20(torchrec%20%3A%20Zain%20Huda)%22%2C%22fbid%22%3A%22711323163133477%22%2C%22photo%22%3A%22%22%7D]%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Ffb%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22tests%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22__init__.py%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fgithub%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fcsrc%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fdatasets%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Finference%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fpt2%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22benchmark%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fmetrics%2F%22%7D]%7D&is_e2e=false&show_all_partitions=false&split_graph=true)

Differential Revision: D77169334
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77169334

jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Jun 26, 2025
Summary:

Main test lies in `test_tensor_weighted_avg.py` (format similar to `test_weighted_avg.py`)

This patch adds a unit test for TensorWeightedAvgMetric. The existing framework for the rec metric testing module does not support processing tensors tied to a task's tensor_name, which the tensor weighted avg metric uses. Main modifications to other tests include changes to the TestMetric's _get_states() method signature to support processing arbitrary tensors in the testing framework.

Increases code coverage to 97.7%. [Previous external tests covered 35%](https://www.internalfb.com/quality/coverage?query=%7B%22key%22%3A%22AND%22%2C%22children%22%3A[%7B%22key%22%3A%22CONTAINS_ANY_OF_FBIDS%22%2C%22field%22%3A%22CODE_QUALITY_ONCALL%22%2C%22value%22%3A[%7B%22title%22%3A%22torchrec%20(torchrec%20%3A%20Zain%20Huda)%22%2C%22fbid%22%3A%22711323163133477%22%2C%22photo%22%3A%22%22%7D]%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Ffb%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22tests%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22__init__.py%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fgithub%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fcsrc%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fdatasets%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Finference%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fpt2%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22benchmark%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fmetrics%2F%22%7D]%7D&is_e2e=false&show_all_partitions=false&split_graph=true)

Differential Revision: D77169334
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77169334

jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Jun 27, 2025
Summary:

Main test lies in `test_tensor_weighted_avg.py` (format similar to `test_weighted_avg.py`)

This patch adds a unit test for TensorWeightedAvgMetric.

TensorWeightedAvgMetric allows users to pass in a tensor that is not a prediction/weight/label with a corresponding tensor name, into a dict called "required_inputs". The purpose is to compute and emit the weighted average of a tensor of their choice.

However, the existing framework for the rec metric testing module does not support processing tensors under "required_inputs". Main modifications to other tests include changes to the TestMetric's _get_states() method signature to support processing tensor passed into "required_inputs".



Increases code coverage to 97.7%. [Previous external tests covered 35%](https://www.internalfb.com/quality/coverage?query=%7B%22key%22%3A%22AND%22%2C%22children%22%3A[%7B%22key%22%3A%22CONTAINS_ANY_OF_FBIDS%22%2C%22field%22%3A%22CODE_QUALITY_ONCALL%22%2C%22value%22%3A[%7B%22title%22%3A%22torchrec%20(torchrec%20%3A%20Zain%20Huda)%22%2C%22fbid%22%3A%22711323163133477%22%2C%22photo%22%3A%22%22%7D]%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Ffb%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22tests%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22__init__.py%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fgithub%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fcsrc%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fdatasets%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Finference%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fpt2%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22benchmark%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fmetrics%2F%22%7D]%7D&is_e2e=false&show_all_partitions=false&split_graph=true)

Reviewed By: kausv

Differential Revision: D77169334
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77169334

jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Jun 30, 2025
Summary:

Main test lies in `test_tensor_weighted_avg.py` (format similar to `test_weighted_avg.py`)

This patch adds a unit test for TensorWeightedAvgMetric.

TensorWeightedAvgMetric allows users to pass in a tensor that is not a prediction/weight/label with a corresponding tensor name, into a dict called "required_inputs". The purpose is to compute and emit the weighted average of a tensor of their choice.

However, the existing framework for the rec metric testing module does not support processing tensors under "required_inputs". Main modifications to other tests include changes to the TestMetric's _get_states() method signature to support processing tensor passed into "required_inputs".



Increases code coverage to 97.7%. [Previous external tests covered 35%](https://www.internalfb.com/quality/coverage?query=%7B%22key%22%3A%22AND%22%2C%22children%22%3A[%7B%22key%22%3A%22CONTAINS_ANY_OF_FBIDS%22%2C%22field%22%3A%22CODE_QUALITY_ONCALL%22%2C%22value%22%3A[%7B%22title%22%3A%22torchrec%20(torchrec%20%3A%20Zain%20Huda)%22%2C%22fbid%22%3A%22711323163133477%22%2C%22photo%22%3A%22%22%7D]%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Ffb%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22tests%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22__init__.py%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fgithub%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fcsrc%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fdatasets%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Finference%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fpt2%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22benchmark%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fmetrics%2F%22%7D]%7D&is_e2e=false&show_all_partitions=false&split_graph=true)

Reviewed By: kausv

Differential Revision: D77169334
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77169334

jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Jun 30, 2025
Summary:
Pull Request resolved: meta-pytorch#3139

Main test lies in `test_tensor_weighted_avg.py` (format similar to `test_weighted_avg.py`)

This patch adds a unit test for TensorWeightedAvgMetric.

TensorWeightedAvgMetric allows users to pass in a tensor that is not a prediction/weight/label with a corresponding tensor name, into a dict called "required_inputs". The purpose is to compute and emit the weighted average of a tensor of their choice.

However, the existing framework for the rec metric testing module does not support processing tensors under "required_inputs". Main modifications to other tests include changes to the TestMetric's _get_states() method signature to support processing tensor passed into "required_inputs".

Increases code coverage to 97.7%. [Previous external tests covered 35%](https://www.internalfb.com/quality/coverage?query=%7B%22key%22%3A%22AND%22%2C%22children%22%3A[%7B%22key%22%3A%22CONTAINS_ANY_OF_FBIDS%22%2C%22field%22%3A%22CODE_QUALITY_ONCALL%22%2C%22value%22%3A[%7B%22title%22%3A%22torchrec%20(torchrec%20%3A%20Zain%20Huda)%22%2C%22fbid%22%3A%22711323163133477%22%2C%22photo%22%3A%22%22%7D]%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Ffb%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22tests%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22__init__.py%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fgithub%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fcsrc%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fdatasets%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Finference%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fpt2%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22benchmark%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fmetrics%2F%22%7D]%7D&is_e2e=false&show_all_partitions=false&split_graph=true)

Reviewed By: kausv

Differential Revision: D77169334
Summary:

Main test lies in `test_tensor_weighted_avg.py` (format similar to `test_weighted_avg.py`)

This patch adds a unit test for TensorWeightedAvgMetric.

TensorWeightedAvgMetric allows users to pass in a tensor that is not a prediction/weight/label with a corresponding tensor name, into a dict called "required_inputs". The purpose is to compute and emit the weighted average of a tensor of their choice.

However, the existing framework for the rec metric testing module does not support processing tensors under "required_inputs". Main modifications to other tests include changes to the TestMetric's _get_states() method signature to support processing tensor passed into "required_inputs".



Increases code coverage to 97.7%. [Previous external tests covered 35%](https://www.internalfb.com/quality/coverage?query=%7B%22key%22%3A%22AND%22%2C%22children%22%3A[%7B%22key%22%3A%22CONTAINS_ANY_OF_FBIDS%22%2C%22field%22%3A%22CODE_QUALITY_ONCALL%22%2C%22value%22%3A[%7B%22title%22%3A%22torchrec%20(torchrec%20%3A%20Zain%20Huda)%22%2C%22fbid%22%3A%22711323163133477%22%2C%22photo%22%3A%22%22%7D]%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Ffb%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22tests%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22__init__.py%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fgithub%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fcsrc%2F%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fdatasets%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Finference%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fpt2%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_NOT_CONTAINS_TEXT%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22benchmark%22%7D%2C%7B%22key%22%3A%22CODE_QUALITY_STARTS_WITH%22%2C%22field%22%3A%22CODE_QUALITY_FILE_PATH%22%2C%22value%22%3A%22fbcode%2Ftorchrec%2Fmetrics%2F%22%7D]%7D&is_e2e=false&show_all_partitions=false&split_graph=true)

Reviewed By: kausv

Differential Revision: D77169334
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77169334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants