[packaging] add support for BytesIO (#50838)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/50838
Similar to `torch.save` and `torch.jit.save`, accept a IO-like object
instead of just a file.
Test Plan: Imported from OSS
Reviewed By: nikithamalgifb
Differential Revision: D25982719
Pulled By: suo
fbshipit-source-id: 42f3665932bbaa6897215002d116df6338edae50