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

[BUG] MaskedOneHotCategorical missing mode and deterministic_sample properties. #2439

Closed
2 of 3 tasks
MorganeAyle opened this issue Sep 17, 2024 · 0 comments · Fixed by #2440
Closed
2 of 3 tasks

[BUG] MaskedOneHotCategorical missing mode and deterministic_sample properties. #2439

MorganeAyle opened this issue Sep 17, 2024 · 0 comments · Fixed by #2440
Assignees
Labels
bug Something isn't working

Comments

@MorganeAyle
Copy link

MorganeAyle commented Sep 17, 2024

Describe the bug

The MaskedOneHotCategorical distribution is missing the mode and deterministic_sample properties.

Reason and Possible fixes

The MaskedOneHotCategorical distribution should overwrite the mode property to account for the conversion to and from one-hot encoding. Additionally, it should implement the deterministic_sample property. Both should be the same as those implemented in OneHotCategorical, i.e.:

@property
def mode(self) -> torch.Tensor:
    if hasattr(self, "logits"):
        return (self.logits == self.logits.max(-1, True)[0]).to(torch.long)
    else:
        return (self.probs == self.probs.max(-1, True)[0]).to(torch.long)

@property
def deterministic_sample(self):
    return self.mode

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have read the documentation (required)
  • I have provided a minimal working example to reproduce the bug (required)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants