allennlp icon indicating copy to clipboard operation
allennlp copied to clipboard

Predictor.from_path using in memory file instead of disk

Open smiles3983 opened this issue 3 years ago • 8 comments

We use openshift, and our enterprise sets limits on ephemeral storage. We need to be able to load a 1.4GB Model and all I see available is Predictor.from_path, which requires the model to be on disk before we can use it. They wont let us use something like S3FS at the moment, so we cant "mount" a network storage location. Is there a way we can take the model that we have loaded into memory as a binary file, and load it to the Predictor directly? We apparently have plenty of RAM to work with.

smiles3983 avatar Apr 09 '21 17:04 smiles3983

We asked the same to Spacy, and they had a response for us. https://github.com/explosion/spaCy/issues/3841

smiles3983 avatar Apr 09 '21 17:04 smiles3983

Hi @smiles3983, so if I'm understanding this correctly, you'd like to have something like a Predictor.from_bytes() method?

epwalsh avatar Apr 09 '21 20:04 epwalsh

Hi @smiles3983, so if I'm understanding this correctly, you'd like to have something like a Predictor.from_bytes() method?

Yes that would be great! Does it exist and I’m just not seeing it?

smiles3983 avatar Apr 09 '21 21:04 smiles3983

It does not exist at the moment, but it's feasible to implement. If you (or someone else) is interested in making a PR to implement this, we'd love to see it. Otherwise I could take a look next week.

epwalsh avatar Apr 09 '21 21:04 epwalsh

Yeah, not sure our team will be able to do it, unless they want to do it from home on their own time :). Dont think we can clone outside our Intranet. We use Nexus to bring down packages. Were open source leeches haha.

smiles3983 avatar Apr 12 '21 17:04 smiles3983

It looks like torch has the ability to load with io.bytesIO. We will be pulling our model from an S3 bucket using s3.get_object(). So if we can convert that to what torch needs without touching the file system.

# Load tensor from io.BytesIO object
>>> with open('tensor.pt', 'rb') as f:
...     buffer = io.BytesIO(f.read())
>>> torch.load(buffer)

smiles3983 avatar Apr 21 '21 12:04 smiles3983

Hi @epwalsh any update on this request... Even I would like to have this configuration.

krishna-anumula avatar Dec 22 '21 13:12 krishna-anumula

Hi @krishna-anumula, I don't have the bandwidth to tackle this at the moment, but I'm happy to review a PR if you'd like to work on it.

epwalsh avatar Dec 22 '21 18:12 epwalsh