LoginSignup
4
1

More than 1 year has passed since last update.

MLflow 2.3のHugging Faceトランスフォーマーのサポートを試す

Posted at

世の中のスピードがすごいと感じる今日この頃です。

こちらのHugging Faceトランスフォーマーのサポートを試しました。

%pip install mlflow==2.3

DollyをHugging Face HubからDollyをロードして、MLflowにロギングします。

Python
import mlflow
import transformers

architecture = "databricks/dolly-v2-3b"

dolly = transformers.pipeline(model=architecture, trust_remote_code=True)

with mlflow.start_run():
    model_info = mlflow.transformers.log_model(
        transformers_model=dolly,
        artifact_path="dolly3b",
        input_example="Hello, Dolly!",
    )

loaded_dolly = mlflow.transformers.load_model(
model_info.model_uri, 
max_new_tokens=250,
)

記録されました!
Screenshot 2023-04-19 at 9.28.35.png

モデルカードもばっちり。
Screenshot 2023-04-19 at 9.29.02.png

次に、ロードしたモデルPyFuncとして活用できるようにしてみます。

Python
import transformers
import mlflow

chat_pipeline = transformers.pipeline(model="microsoft/DialoGPT-medium")

with mlflow.start_run():
  model_info = mlflow.transformers.log_model(
    transformers_model=chat_pipeline,
    artifact_path="chatbot",
    input_example="Hi there!"
  )

# Load as interactive pyfunc

chatbot = mlflow.pyfunc.load_model(model_info.model_uri)

南極大陸に行くベストな方法は?

Python
chatbot.predict("What is the best way to get to Antarctica?")

ボートでそこに行けると思います。

Out[3]: 'I think you can get there by boat.'

そうですか…。

次は、OpenAIのAPIのフレーバーを試してみます。

Databricksクイックスタートガイド

Databricksクイックスタートガイド

Databricks無料トライアル

Databricks無料トライアル

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1