Add factory function derivatives (#79872)
Adding derivatives for factory functions, this issue is used for tracking: #79044
Pull Request resolved: https://github.com/pytorch/pytorch/pull/79872
Approved by: https://github.com/cpuhrsch, https://github.com/soulitzer