# reinforcement-learning

**URL:** https://discuss.pytorch.org/c/reinforcement-learning/6.md?page=3

[Latest](https://discuss.pytorch.org/latest.md) · [Categories](https://discuss.pytorch.org/categories.md)

**Page:** 4

---

## [How to use ParallelEnv?](https://discuss.pytorch.org/t/how-to-use-parallelenv/201042)

<div class="topic-metadata">

**Author:** [@Vefery](https://discuss.pytorch.org/u/Vefery)\
**Replies:** 3\
**Last updated:** [May 29, 2024, 1:13pm UTC](https://discuss.pytorch.org/t/how-to-use-parallelenv/201042 "2024-05-29T13:13:36Z")

</div>

I finished this guide and in the end there’s a note at the end that I can use ParallelEnv env to speed up data collection. I couldn’t find any examples or information about this besides documentation page. So I tried to …

---

## [Does ModuleList behaves differently from Sequence](https://discuss.pytorch.org/t/does-modulelist-behaves-differently-from-sequence/52822)

<div class="topic-metadata">

**Author:** [@Pengbo\_Ma](https://discuss.pytorch.org/u/Pengbo_Ma)\
**Replies:** 12\
**Last updated:** [May 28, 2024, 10:11am UTC](https://discuss.pytorch.org/t/does-modulelist-behaves-differently-from-sequence/52822 "2024-05-28T10:11:15Z")

</div>

Hi there, I was trying to implement a A2C model to train one of the OpenGym project. I created two models that are identical to me in terms of structure and forward logic. The main difference between the two models is …

---

## [Memory leak in Drqv2](https://discuss.pytorch.org/t/memory-leak-in-drqv2/203340)

<div class="topic-metadata">

**Author:** [@zichunxx](https://discuss.pytorch.org/u/zichunxx)\
**Replies:** 0\
**Last updated:** [May 24, 2024, 2:03am UTC](https://discuss.pytorch.org/t/memory-leak-in-drqv2/203340 "2024-05-24T02:03:11Z")

</div>

Hi! I’m a rookie at reinforcement learning and trying to reproduce the result of Drqv2. However, I met the memory leak problem when training drqv2 with 2,000,000+ training frames, which is categorized as a medium or ha…

---

## [DDPG ounoise inplace operation error](https://discuss.pytorch.org/t/ddpg-ounoise-inplace-operation-error/202932)

<div class="topic-metadata">

**Author:** [@jack70703350](https://discuss.pytorch.org/u/jack70703350)\
**Replies:** 0\
**Last updated:** [May 17, 2024, 7:03am UTC](https://discuss.pytorch.org/t/ddpg-ounoise-inplace-operation-error/202932 "2024-05-17T07:03:31Z")

</div>

Hi everyone, I’m working on two link robot arm control using DDPG. My custom environment is like reacher in Mujoco environment and I’m trying to train my robot arm fingertip to follow specific trajectory (i.e. circle). I…

---

## [How to use GRU/LSTM is RL?](https://discuss.pytorch.org/t/how-to-use-gru-lstm-is-rl/124650)

<div class="topic-metadata">

**Author:** [@Ayman\_Al\_Jabri](https://discuss.pytorch.org/u/Ayman_Al_Jabri)\
**Replies:** 9\
**Last updated:** [May 14, 2024, 8:51am UTC](https://discuss.pytorch.org/t/how-to-use-gru-lstm-is-rl/124650 "2024-05-14T08:51:51Z")

</div>

Hi all, I want to add memory cell/layer to my model to improve performance on Atari games. But I’m not sure if I’m doing it right! If I understood recurrent networks correctly, they take a sequence of observations from…

---

## [Contribution: Stateless TicTacToe](https://discuss.pytorch.org/t/contribution-stateless-tictactoe/202102)

<div class="topic-metadata">

**Author:** [@DuaneNielsen](https://discuss.pytorch.org/u/DuaneNielsen)\
**Replies:** 0\
**Last updated:** [May 4, 2024, 8:14pm UTC](https://discuss.pytorch.org/t/contribution-stateless-tictactoe/202102 "2024-05-04T20:14:23Z")

</div>

Contributing a stateless TicTacToe implementation in pytorch RL. Comes with a play script… to play it… just click on the matplotlib script using the mouse. import torch from torchrl.envs import EnvBase, O…

---

## [Why Pytorch is much slower than Python dictionary?](https://discuss.pytorch.org/t/why-pytorch-is-much-slower-than-python-dictionary/201715)

<div class="topic-metadata">

**Author:** [@ch0t0n](https://discuss.pytorch.org/u/ch0t0n)\
**Replies:** 0\
**Last updated:** [April 27, 2024, 4:08pm UTC](https://discuss.pytorch.org/t/why-pytorch-is-much-slower-than-python-dictionary/201715 "2024-04-27T16:08:25Z")

</div>

Please if anybody knows the answer to my question that I asked in stackoverflow, it would be really helpful. Here is the link: Why Pytorch is much slower than Python dictionary? - Stack Overflow

---

## [Contextual Bandit with PyTorch instead of TF?](https://discuss.pytorch.org/t/contextual-bandit-with-pytorch-instead-of-tf/171697)

<div class="topic-metadata">

**Author:** [@arvnoodle](https://discuss.pytorch.org/u/arvnoodle)\
**Replies:** 4\
**Last updated:** [April 23, 2024, 8:50pm UTC](https://discuss.pytorch.org/t/contextual-bandit-with-pytorch-instead-of-tf/171697 "2024-04-23T20:50:04Z")

</div>

So I saw there’s a TF agent that can do Linear Thompson Sampling but was hoping for if there’s a similar Pytorch implementation of that? If you guys know anything? Planning to use it for Send Time Optimization

---

## [What does ProbabilisticActor model output?](https://discuss.pytorch.org/t/what-does-probabilisticactor-model-output/201041)

<div class="topic-metadata">

**Author:** [@Vefery](https://discuss.pytorch.org/u/Vefery)\
**Replies:** 0\
**Last updated:** [April 16, 2024, 7:28pm UTC](https://discuss.pytorch.org/t/what-does-probabilisticactor-model-output/201041 "2024-04-16T19:28:11Z")

</div>

I followed this guide and trained the model. Then I saved the full model and tried to use it for inference. But the loaded model outputs a tuple of 4 tensors (3 tensors of the length of actions number and one tensor with…

---

## [Calling torch.distributions.categorical.Categorical multiple times can affect the final result](https://discuss.pytorch.org/t/calling-torch-distributions-categorical-categorical-multiple-times-can-affect-the-final-result/200238)

<div class="topic-metadata">

**Author:** [@wqingze](https://discuss.pytorch.org/u/wqingze)\
**Replies:** 3\
**Last updated:** [April 7, 2024, 3:32pm UTC](https://discuss.pytorch.org/t/calling-torch-distributions-categorical-categorical-multiple-times-can-affect-the-final-result/200238 "2024-04-07T15:32:20Z")

</div>

Calling torch.distributions.categorical.Categorical multiple times can affect the final result. In the PPO (Proximal Policy Optimization) algorithm, the action function is defined as follows: def choose\_action(self, s,…

---

## [GPU out of memory for simple RLHF](https://discuss.pytorch.org/t/gpu-out-of-memory-for-simple-rlhf/200256)

<div class="topic-metadata">

**Author:** [@yehhhh](https://discuss.pytorch.org/u/yehhhh)\
**Replies:** 0\
**Last updated:** [April 4, 2024, 5:16pm UTC](https://discuss.pytorch.org/t/gpu-out-of-memory-for-simple-rlhf/200256 "2024-04-04T17:16:28Z")

</div>

Hello everyone, I am trying to implement a simple policy gradient for fine-tuning an autoregressive transformer from scratch, but got CUDA memory error issue when I try to use batch size 64 and have a long sequence (\>10…

---

## [Evaluating a pretrained model](https://discuss.pytorch.org/t/evaluating-a-pretrained-model/200200)

<div class="topic-metadata">

**Author:** [@juripf](https://discuss.pytorch.org/u/juripf)\
**Replies:** 0\
**Last updated:** [April 3, 2024, 7:27pm UTC](https://discuss.pytorch.org/t/evaluating-a-pretrained-model/200200 "2024-04-03T19:27:14Z")

</div>

I’m trying to evaluate a pretrained model that i trained with the PPO example from the pytorch tutorials website but i’m failing to obtain the same results as during training. I’ve saved the model (in the train script) …

---

## [Guidance for RL course & torchRL](https://discuss.pytorch.org/t/guidance-for-rl-course-torchrl/199904)

<div class="topic-metadata">

**Author:** [@deependujha](https://discuss.pytorch.org/u/deependujha)\
**Replies:** 0\
**Last updated:** [March 31, 2024, 3:55am UTC](https://discuss.pytorch.org/t/guidance-for-rl-course-torchrl/199904 "2024-03-31T03:55:32Z")

</div>

I’m very comfortable with pytorch, torchvision and torchtext. Now, I’m trying to get my hands on torchRL & be a confident reinforcement learning engineer. My current roadmap is: CS-285 course by Sergey Levine RL book …

---

## [Why is loss not converging?](https://discuss.pytorch.org/t/why-is-loss-not-converging/199575)

<div class="topic-metadata">

**Author:** [@CMJr](https://discuss.pytorch.org/u/CMJr)\
**Replies:** 0\
**Last updated:** [March 25, 2024, 11:38pm UTC](https://discuss.pytorch.org/t/why-is-loss-not-converging/199575 "2024-03-25T23:38:12Z")

</div>

I’m trying to make a deep Q network for the Lunar Lander v2 environment. I got the model to run, but it isn’t converging at all; the loss and environment rewards aren’t improving. What’s wrong with my code? Here’s a l…

---

## [MADDPG RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation](https://discuss.pytorch.org/t/maddpg-runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation/199557)

<div class="topic-metadata">

**Author:** [@Luis\_Barba](https://discuss.pytorch.org/u/Luis_Barba)\
**Replies:** 0\
**Last updated:** [March 25, 2024, 5:25pm UTC](https://discuss.pytorch.org/t/maddpg-runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation/199557 "2024-03-25T17:25:24Z")

</div>

Hey everyone im trying to implement MADDPG but when the second agent tries to do a backward pass on the critic loss I am met with the following error: Blockquote File “”, line 536, in maddppg\_agents.learn(memory, i…

---

## [How to use PPOLoss with shared actor and critic parameters?](https://discuss.pytorch.org/t/how-to-use-ppoloss-with-shared-actor-and-critic-parameters/199498)

<div class="topic-metadata">

**Author:** [@kf064](https://discuss.pytorch.org/u/kf064)\
**Replies:** 0\
**Last updated:** [March 25, 2024, 3:06am UTC](https://discuss.pytorch.org/t/how-to-use-ppoloss-with-shared-actor-and-critic-parameters/199498 "2024-03-25T03:06:10Z")

</div>

I am training an actor-critic model in a reinforcement learning environment which processes observations in a shared hidden module before passing the data to the policy and value heads as shown in this diagram. The PyTo…

---

## [Custom Neural Network Environment](https://discuss.pytorch.org/t/custom-neural-network-environment/199165)

<div class="topic-metadata">

**Author:** [@ptrem](https://discuss.pytorch.org/u/ptrem)\
**Replies:** 0\
**Last updated:** [March 19, 2024, 9:05am UTC](https://discuss.pytorch.org/t/custom-neural-network-environment/199165 "2024-03-19T09:05:12Z")

</div>

Hi, I’m new in the field of reinforcement learning and currently searching for a suitable library to implement my deep reinforcement learning research project. It should be a Python library and use PyTorch for the deep …

---

## [While training RLHF model I am getting error like, ValueError: num\_samples should be a positive integer value, but got num\_samples=0](https://discuss.pytorch.org/t/while-training-rlhf-model-i-am-getting-error-like-valueerror-num-samples-should-be-a-positive-integer-value-but-got-num-samples-0/198889)

<div class="topic-metadata">

**Author:** [@OpenEyes\_VO](https://discuss.pytorch.org/u/OpenEyes_VO)\
**Replies:** 0\
**Last updated:** [March 14, 2024, 12:56pm UTC](https://discuss.pytorch.org/t/while-training-rlhf-model-i-am-getting-error-like-valueerror-num-samples-should-be-a-positive-integer-value-but-got-num-samples-0/198889 "2024-03-14T12:56:45Z")

</div>

I am using above code for training RLHF for answer generation. learning\_rate=1.41e-5 max\_ppo\_epochs=1 mini\_batch\_size=4 batch\_size=16 config = PPOConfig( model\_name=model\_name, learning\_rate=learning\_rate, …

---

## [Warning when using RPC](https://discuss.pytorch.org/t/warning-when-using-rpc/198009)

<div class="topic-metadata">

**Author:** [@wilhelm](https://discuss.pytorch.org/u/wilhelm)\
**Replies:** 1\
**Last updated:** [March 13, 2024, 8:55pm UTC](https://discuss.pytorch.org/t/warning-when-using-rpc/198009 "2024-03-13T20:55:51Z")

</div>

I’m following this tutorial for RPC in PyTorch. The problem is that running that code I get the following warning: /opt/anaconda/anaconda3/envs/dl-gym/lib/python3.10/site-packages/torch/distributed/distributed\_c10d.py…

---

## [Can anyone help me, i want to make project anomaly detection water consumption using dqn, below is my dataset](https://discuss.pytorch.org/t/can-anyone-help-me-i-want-to-make-project-anomaly-detection-water-consumption-using-dqn-below-is-my-dataset/198806)

<div class="topic-metadata">

**Author:** [@Andhika\_Ahnaf\_Danisw](https://discuss.pytorch.org/u/Andhika_Ahnaf_Danisw)\
**Replies:** 1\
**Last updated:** [March 13, 2024, 3:45pm UTC](https://discuss.pytorch.org/t/can-anyone-help-me-i-want-to-make-project-anomaly-detection-water-consumption-using-dqn-below-is-my-dataset/198806 "2024-03-13T15:45:04Z")

</div>

---

## [Do TorchRL environments have a way to handle policies that outputs trajectories?](https://discuss.pytorch.org/t/do-torchrl-environments-have-a-way-to-handle-policies-that-outputs-trajectories/198794)

<div class="topic-metadata">

**Author:** [@Alexander\_Soare](https://discuss.pytorch.org/u/Alexander_Soare)\
**Replies:** 6\
**Last updated:** [March 13, 2024, 3:30pm UTC](https://discuss.pytorch.org/t/do-torchrl-environments-have-a-way-to-handle-policies-that-outputs-trajectories/198794 "2024-03-13T15:30:28Z")

</div>

I’m working with policies that, given observations, output a fixed-horizon action trajectory. Once that horizon is consumed, we rinse and repeat. My current setup is to absorb that logic into the environment with a loop …

---

## [Training gets slow down by each batch slowly](https://discuss.pytorch.org/t/training-gets-slow-down-by-each-batch-slowly/4460)

<div class="topic-metadata">

**Author:** [@cosmmb](https://discuss.pytorch.org/u/cosmmb)\
**Replies:** 30\
**Last updated:** [March 9, 2024, 10:05pm UTC](https://discuss.pytorch.org/t/training-gets-slow-down-by-each-batch-slowly/4460 "2024-03-09T22:05:07Z")

</div>

Hi there, I have a pre-trained model, and I added an actor-critic method into the model and trained only on the rl-related parameter (I fixed the parameters from pre-trained model). However, I noticed that the training…

---

## [RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation - REINFORCE Algorithm](https://discuss.pytorch.org/t/runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-reinforce-algorithm/198129)

<div class="topic-metadata">

**Author:** [@vaduma\_263](https://discuss.pytorch.org/u/vaduma_263)\
**Replies:** 0\
**Last updated:** [March 3, 2024, 5:26pm UTC](https://discuss.pytorch.org/t/runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-reinforce-algorithm/198129 "2024-03-03T17:26:41Z")

</div>

I get a “RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation:” when I run the following supposedly simple reinforcement learning code. import torch import torch.…

---

## [Backpropagation rule for REINFORCE weight updates using a Multinomial distribution](https://discuss.pytorch.org/t/backpropagation-rule-for-reinforce-weight-updates-using-a-multinomial-distribution/117395)

<div class="topic-metadata">

**Author:** [@Bick95](https://discuss.pytorch.org/u/Bick95)\
**Replies:** 2\
**Last updated:** [February 29, 2024, 1:01am UTC](https://discuss.pytorch.org/t/backpropagation-rule-for-reinforce-weight-updates-using-a-multinomial-distribution/117395 "2024-02-29T01:01:35Z")

</div>

Hello, I am implementing a REINFORCE algorithm (as superficially explained over here) using a Categorical distribution (or Multinomial distribution as argued in the explanation of the Categorical distribution) for sampl…

---

## [Modified PPO Example: loss\_value.backward(retain\_graph=True)?](https://discuss.pytorch.org/t/modified-ppo-example-loss-value-backward-retain-graph-true/197331)

<div class="topic-metadata">

**Author:** [@kgetzand](https://discuss.pytorch.org/u/kgetzand)\
**Replies:** 1\
**Last updated:** [February 27, 2024, 8:18am UTC](https://discuss.pytorch.org/t/modified-ppo-example-loss-value-backward-retain-graph-true/197331 "2024-02-27T08:18:35Z")

</div>

Hi all, I’ve modified the PPO tutorial to use a custom environment. However, in the training step, when I call “loss\_value.backward()” it eventually throws “RuntimeError: Trying to backward through the graph a second ti…

---

## [How to save a trained model in a PPO sample](https://discuss.pytorch.org/t/how-to-save-a-trained-model-in-a-ppo-sample/197267)

<div class="topic-metadata">

**Author:** [@4gv8pein](https://discuss.pytorch.org/u/4gv8pein)\
**Replies:** 4\
**Last updated:** [February 24, 2024, 2:52pm UTC](https://discuss.pytorch.org/t/how-to-save-a-trained-model-in-a-ppo-sample/197267 "2024-02-24T14:52:14Z")

</div>

I am learning the PPO sample code in the tutorial linked below. https://pytorch.org/rl/tutorials/coding\_ppo.html I want to save a learned model of PPO that is reproducible as I will be doing multiple tests against PPO.…

---

## [RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: \[torch.FloatTensor \[3, 1\]\], which is output 0 of TanhBackward, is at version 1; expected version 0 instead](https://discuss.pytorch.org/t/runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-torch-floattensor-3-1-which-is-output-0-of-tanhbackward-is-at-version-1-expected-version-0-instead/87630)

<div class="topic-metadata">

**Author:** [@Se\_di](https://discuss.pytorch.org/u/Se_di)\
**Replies:** 31\
**Last updated:** [February 23, 2024, 1:57pm UTC](https://discuss.pytorch.org/t/runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-torch-floattensor-3-1-which-is-output-0-of-tanhbackward-is-at-version-1-expected-version-0-instead/87630 "2024-02-23T13:57:17Z")

</div>

Hey, I’m getting this error but i don’t understand why it has a problem with ‘action\_value = torch.tanh(self.action\_values(x))’ when I use relu or hardtanh there is no problem. class NAF(nn.Module): def \_\_init\_\_(se…

---

## [Need help with the LSTM classifier](https://discuss.pytorch.org/t/need-help-with-the-lstm-classifier/197301)

<div class="topic-metadata">

**Author:** [@MininDm](https://discuss.pytorch.org/u/MininDm)\
**Replies:** 0\
**Last updated:** [February 19, 2024, 8:35am UTC](https://discuss.pytorch.org/t/need-help-with-the-lstm-classifier/197301 "2024-02-19T08:35:57Z")

</div>

Hello everyone, I am developing a system that will classify the load on a block device in a storage system. I’m going to train the model on the already collected sequences, and with the inference, the data will come in t…

---

## [Curriculum Learning in torchRL?](https://discuss.pytorch.org/t/curriculum-learning-in-torchrl/196720)

<div class="topic-metadata">

**Author:** [@Kevin\_Fu](https://discuss.pytorch.org/u/Kevin_Fu)\
**Replies:** 1\
**Last updated:** [February 7, 2024, 7:46am UTC](https://discuss.pytorch.org/t/curriculum-learning-in-torchrl/196720 "2024-02-07T07:46:19Z")

</div>

Hi, I would like to implement a curriculum learning framework in torchRL. Specifically, I would like to increase the number of agents in an environment after a certain number of epochs or certain average reward reached i…

---

## [Fighting against distributions Categorical: log\_prob is delivering unexpected values](https://discuss.pytorch.org/t/fighting-against-distributions-categorical-log-prob-is-delivering-unexpected-values/196204)

<div class="topic-metadata">

**Author:** [@wilhelm](https://discuss.pytorch.org/u/wilhelm)\
**Replies:** 1\
**Last updated:** [February 2, 2024, 3:28pm UTC](https://discuss.pytorch.org/t/fighting-against-distributions-categorical-log-prob-is-delivering-unexpected-values/196204 "2024-02-02T15:28:26Z")

</div>

I’m trying to implement the CartPole-v1 problem from the Book “Introduction into RL” by trying to adapt their code posted in their repository here: link. Their code is old, so I changed it for working with Gymnasium 0.2…

[Previous page](https://discuss.pytorch.org/c/reinforcement-learning/6.md?page=2)

[Next page](https://discuss.pytorch.org/c/reinforcement-learning/6.md?page=4)
