HI,there is weird issue.Everything was fine till now,but as soon as i restarted the kernel in jupyter, the grad wrt variables is again nonetype.I think there is still some issue as this error was resolved once i pasted  and ran your code in a seperate cell.Then i ran my loop which i have provided above,everything is fine.And btw i initialise ht_1 just like you did.