Closed Marcusntnu closed 1 year ago
Sorry for the issue posting if it's not the most suitable. What I'm really trying to do is optimize some inference pipeline, could also be with dataloader.
If not very suitable feel free to close.
This looks roughly correct to me, can you explain what the issue is (or why it doesn't run at the moment)?
This is some code that I've used for (batched) captioning. It is roughly the same as what you have, but maybe it will still be helpful:
embeddings = model.model.get_visual_embs(images)
input_ids = tokenizer('A picture of', add_special_tokens=True, return_tensors="pt").input_ids.to(images.device)
prompt_embeddings = meta_model.model.input_embeddings(input_ids)
prompt_embeddings = prompt_embeddings.repeat([images.shape[0], 1, 1])
embeddings = torch.cat([embeddings, prompt_embeddings], dim=1)
gen_id, _, _ = meta_model.model.generate(embeddings, max_len=32, min_word_tokens=32)
gen_cap = meta_model.model.tokenizer.batch_decode(gen_id, skip_special_tokens=True)
gen_cap
will be a list of text captions. Each one is decoded to 32 words (for batching purposes), so you will have to do some postprocessing to truncate it (e.g., to the first period) and such.
Hi, trying to make a huggingface pipeline so I can run batched inference. Any ideas? Here's my attempt at a pipeline so far. With the current examples I'm not able to do batching.
' class FromagePipeline(Pipeline): def _sanitize_parameters(self, **kwargs): preprocess_kwargs = {} if "meta_model" in kwargs: self.meta_model = kwargs["meta_model"] return preprocess_kwargs, {}, {}
'