Skip to content

Support RecMetrics new options in Pyper config #2987

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions torchrec/metrics/tower_qps.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,14 @@ def update(
RecComputeMode.FUSED_TASKS_AND_STATES_COMPUTATION,
]:
if not isinstance(labels, torch.Tensor):
raise RecMetricException(
"Fused computation only support where 'labels' is a tensor"
)
try:
labels = torch.stack(
[labels[task.name] for task in self._tasks]
)
except Exception as e:
raise RecMetricException(
f"Failed to convert labels to tensor for fused computation: {e}"
)
labels = labels.view(-1, self._batch_size)
if self._should_validate_update:
# Set the default value to be all True. When weights is None, it's considered
Expand All @@ -241,9 +246,14 @@ def update(
)
if weights is not None:
if not isinstance(weights, torch.Tensor):
raise RecMetricException(
"Fused computation only support where 'weights' is a tensor"
)
try:
weights = torch.stack(
[weights[task.name] for task in self._tasks]
)
except Exception as e:
raise RecMetricException(
f"Failed to convert weights to tensor for fused computation: {e}"
)
has_valid_weights = torch.gt(
torch.count_nonzero(
weights.view(-1, self._batch_size), dim=-1
Expand Down
Loading