pytorch / pytorch/rl

[Feature Request] Add MaskedCategorical Distribution

Open
#1,013 0 comments 1 reaction 1 assignee View on GitHub

@vmoens is already working on this.

Since Mar 31, 2023.

enhancement
Dominant language
Python
Stars
3.6k
Forks
487
Avg merge
1d 1h
Merged PRs (30d)
207

Description

Motivation

In RL use cases, it is very common that we have an action mask to only choose from valid actions. Then in such cases, MaskedCategorical distribution can be helpful to sample and compute log_prob and entropy.

Solution

Add a MaskedCategorical like TFAgents
https://www.tensorflow.org/agents/api_docs/python/tf_agents/distributions/masked/MaskedCategorical

Here we also need to add a sparse_mask argument to support passing mask as a sparse_vector. This is helpful especially in RLHF cases. In Language Models, the action space is vocab_size which is pretty large, but the number of candidate actions can be much smaller, then it can help to improve both speed and space with sparse_mask. An example of sparse_mask is shown below.

Alternatives

In RL with action masks cases, we can manually mask the logits to implement this.

Additional context

Add any other context or screenshots about the feature request here.

Checklist

  • I have checked that there is no similar issue in the repo (required)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.