I have now created get_action4():
    def get_action4(self, SYS, state):
        #////////////////////////////////////////////////
        qvals = self.DQN.model(self.state)
        #////////////////////////////////////////////////
        self.action = torch.argmax(qvals, dim=1).item()
        #////////////////////////////////////////////////
        return(self.action)

an run the boot loop inside torch.no_grad():
        with torch.no_grad():
            while not done:

bootstrap examples: 100%|██████████| 32000/32000 [00:13<00:00, 2426.59 item(s)/s]
That also does not help, sorry. Thank you for your help anyway and I’m sorry that I took so much of your time. It is really sad but unfortunately I have to stay with Keras / Theano under these circumstances. In my case, this “little differences” mean that I would have several hours more training time.
By the way, I experienced almost the same story with Tensorflow. I started with Keras / Theano, then I spent weeks working with Tensorflow, various environments from Intel / Conda-Forge and so on. No matter what I tried, everything was slower than Theano.
And now the same with PyTorch, I never would have thought that…
Fortunately, I don’t have to understand in detail how gather () and backward () work.