Skip to content

Note that dropout stays active during sampling in char-RNN generation tutorial - #3998

Open
Raushan2102 wants to merge 1 commit into
pytorch:mainfrom
Raushan2102:docs-char-rnn-dropout-sampling
Open

Raushan2102 wants to merge 1 commit into
pytorch:mainfrom
Raushan2102:docs-char-rnn-dropout-sampling

Conversation

@Raushan2102

Copy link
Copy Markdown

Description

sample() in char_rnn_generation_tutorial.py picks the top letter (topk(1)), but rnn is never put in eval() mode, and torch.no_grad() does not disable nn.Dropout. As a result, greedy sampling returns a different name on each call. The tutorial uses dropout for sampling variety on purpose, so this PR does not change any code. It adds a short note explaining why the samples vary and how to get repeatable output (rnn.eval(), then rnn.train() before training again).

Reproduction (tutorial's RNN, train() and sample(), PyTorch 2.1.1): 20 calls to sample() gave 7–10 distinct names per category in training mode and 1 after rnn.eval().

I could not find an existing issue for this. Related: #3956 changes the same tutorial but does not touch dropout or sampling.

AI assistance was used to find the issue and draft the note; I reproduced the result locally.

Checklist

  • The issue that is being fixed is referred in the description (no existing issue; see above)
  • Only one issue is addressed in this pull request
  • Labels from the issue that this PR is fixing are added to this pull request
  • No unnecessary issues are included into this pull request.

@pytorch-bot

pytorch-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3998

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the cla signed label Nov 13, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/docs

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant