huggingface / optimum-neuron

Easy, fast and very cheap training and inference on AWS Trainium and Inferentia chips.
Apache License 2.0
176 stars 53 forks source link

Support phi model on feature-extraction, text-classification, token-classification tasks #509

Closed JingyaHuang closed 3 months ago

JingyaHuang commented 3 months ago

What does this PR do?

Support phi family models on feature-extraction, text-classification, token-classification tasks.

Fixes #508


Export

optimum-cli export neuron --model microsoft/phi-1_5 --sequence_length 64 --batch_size 1 --task text-classification phi1_5/

Inference

from transformers import AutoTokenizer
from optimum.neuron import NeuronModelForSequenceClassification

model_id = "phi1_5/"
text = "This is a sample output"
tokenizer = AutoTokenizer.from_pretrained(model_id)
neuron_model = NeuronModelForSequenceClassification.from_pretrained(model_id)
inputs = tokenizer(text, return_tensors="pt")
neuron_outputs = neuron_model(**inputs)

Before submitting

HuggingFaceDocBuilderDev commented 3 months ago

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

JingyaHuang commented 3 months ago

Update styling tool and fix style following this:

Run source venv/bin/activate
  source venv/bin/activate
  ruff .
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.8.18/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.8.18/x64/lib
warning: `ruff <path>` is deprecated. Use `ruff check <path>` instead.
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `pyproject.toml`:
  - 'ignore' -> 'lint.ignore'
  - 'select' -> 'lint.select'
  - 'isort' -> 'lint.isort'
  - 'per-file-ignores' -> 'lint.per-file-ignores'
text-generation-inference/server/text_generation_server/model.py:1[2](https://github.com/huggingface/optimum-neuron/actions/runs/8216181267/job/22470453310?pr=509#step:7:2)9:[5](https://github.com/huggingface/optimum-neuron/actions/runs/8216181267/job/22470453310?pr=509#step:7:5): E[7](https://github.com/huggingface/optimum-neuron/actions/runs/8216181267/job/22470453310?pr=509#step:7:7)22 Do not use bare `except`
Found 1 error.