[package] implement get_resource_reader API (#51674)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51674

See
https://docs.python.org/3/library/importlib.html#importlib.abc.ResourceReader

Test Plan: Imported from OSS

Reviewed By: zdevito

Differential Revision: D26237034

Pulled By: suo

fbshipit-source-id: 4c19f6172d16b710737528d3de48372873b9368d
This commit is contained in:
Michael Suo
2021-03-10 12:04:02 -08:00
committed by Facebook GitHub Bot
parent bfc80b3566
commit b4d8f4af82
4 changed files with 145 additions and 14 deletions

View File

@ -991,6 +991,11 @@ void initJITBindings(PyObject* module) {
std::tie(data, size) = self.getRecord(key);
return py::bytes(reinterpret_cast<const char*>(data.get()), size);
})
.def(
"has_record",
[](PyTorchStreamReader& self, const std::string& key) {
return self.hasRecord(key);
})
.def(
"get_storage_from_record",
[](PyTorchStreamReader& self,