Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Add Support for Different Model Types #4

Open
cderinbogaz opened this issue Sep 28, 2022 · 1 comment
Open

Add Support for Different Model Types #4

cderinbogaz opened this issue Sep 28, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@cderinbogaz
Copy link

cderinbogaz commented Sep 28, 2022

ONNX models are serialised version of the current AI models. They are a bit faster from the normal pytorch or huggingface therefore some users might want to use this type of models.

We already do have a model converted and added to huggingface:
https://huggingface.co/TextCortex/codegen-350M-optimized

In total we need to support following model types:

  • Pytorch: Filename extension .pt
  • Hugginface: Filename extension .bin
  • ONNX: Filename extension .onnx

Here is the script for supporting text generation for ONNX models with optimum library from huggingface:

from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForCausalLM
# Load models
model = ORTModelForCausalLM.from_pretrained("TextCortex/codegen-350M-optimized")
tokenizer = AutoTokenizer.from_pretrained("TextCortex/codegen-350M-optimized")

def generate_onnx(prompt, min_length=16, temperature=0.1, num_return_sequences=1):
   generated_ids=model.generate(input_ids, min_length=min_length, temperature=temperature,
                                   num_return_sequences=num_return_sequences, early_stopping=True)
   out = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
   return out

For the Vanilla Pytorch models .pt, you can directly use AutoModel class from transformers (which also works for the huggingface .bin model types.)

@cderinbogaz cderinbogaz added the enhancement New feature or request label Sep 28, 2022
@osolmaz
Copy link
Collaborator

osolmaz commented Oct 3, 2022

This feature is mostly implemented, there are some small tasks left to do:

  • HuggingFace model config handling

@osolmaz osolmaz self-assigned this Oct 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants