I have developed the mlops pipline using sagemaker in aws, the pipeline and code are all set correctly and every step is succeeded, before that I was working on the model in kaggle and I found a ressource that helped me extract the data from receipt,
this is the code I’m talking about
image = example['image']
pixel_ = processor(image, return_tensors="pt").pixel_values
import torch
task_prompt = "<s_cord-v2>"
decoder_input_ids = processor.tokenizer(task_prompt, add_special_tokens=False, return_tensors="pt")["input_ids"]
device = "cuda" if torch.cuda.is_available() else "cpu"
outputs = model.generate(pixel_.to(device),
decoder_input_ids=decoder_input_ids.to(device),
max_length=model_module.model.decoder.config.max_position_embeddings,
early_stopping=True,
pad_token_id=processor.tokenizer.pad_token_id,
eos_token_id=processor.tokenizer.eos_token_id,
use_cache=True,
num_beams=1,
bad_words_ids=[[processor.tokenizer.unk_token_id]],
return_dict_in_generate=True,
output_scores=True,)
sequence = processor.batch_decode(outputs.sequences)[0]
sequence = sequence.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
processor.token2json(sequence)
this code is working correctly, returning to the sagemaker mlops now, the endpoint now is created, but I don’t know how to put this code into the lambda function since I think that this is the only way, and the thing is this code is using processor and model.
I try to make the lambda function but I can’t find the correct approach and solution, and this don’t gave me any result, Is there any suggestion how to implement this, or a suggestion about how to make the lambda function work.