Frankly I do not see any errors with the lines you have shared. I just ran your first post and it works. Do you want to create a notebook on google colab with a toy example and share the link so I can take a deeper look?