Giter Site home page Giter Site logo

Comments (3)

philschmid avatar philschmid commented on August 10, 2024

There is a PR for this already, which will be merged today. #2
This PR adds the model as input parameter for predict

from sagemaker-huggingface-inference-toolkit.

la-cruche avatar la-cruche commented on August 10, 2024

ok perfect. Yes indeed, with the current predict_fn(processed_data) the inference fails with a W-model-1-stdout com.amazonaws.ml.mms.wlm.WorkerLifeCycle - mms.service.PredictionException: name 'model' is not defined : 400

I'm using the below functions

def load_fn(model_dir):
    """this function reads the model from disk"""
    
    print('load_fn dir view:')
    print(os.listdir())
    
    # load model
    model = TFAutoModelForQuestionAnswering.from_pretrained('/opt/ml/model')
    
    # load tokenizer
    tokenizer = AutoTokenizer.from_pretrained('/opt/ml/model')
    
    return model, tokenizer




def predict_fn(processed_data):
    """this function runs inference"""

    print('processed_data received: ')
    print(processed_data)
    
    print('model name:')
    print(model.name)

    print('tok name:')
    print(tokenizer.name)   
    
    question, text = processed_data['inputs']['question'], processed_data['inputs']['context']

    input_dict = tokenizer(question, text, return_tensors='tf')
    outputs = model(input_dict)
    start_logits = outputs.start_logits
    end_logits = outputs.end_logits
    
    all_tokens = tokenizer.convert_ids_to_tokens(input_dict["input_ids"].numpy()[0])
    answer = ' '.join(all_tokens[tf.math.argmax(start_logits, 1)[0] : tf.math.argmax(end_logits, 1)[0]+1])
    
    return answer

from sagemaker-huggingface-inference-toolkit.

la-cruche avatar la-cruche commented on August 10, 2024

with the new predict_fn(processed_data, model) things work fine as documented here #10 (comment)

from sagemaker-huggingface-inference-toolkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.