Skip to content

Commit

Permalink
Add documentations for PEFT and save_pretrained option (#11232)
Browse files Browse the repository at this point in the history
Signed-off-by: B-Step62 <yuki.watanabe@databricks.com>
  • Loading branch information
B-Step62 committed Feb 27, 2024
1 parent 7efd964 commit b8561ee
Show file tree
Hide file tree
Showing 12 changed files with 445 additions and 183 deletions.
Expand Up @@ -4,7 +4,20 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Serving LLMs with MLflow: Leveraging Custom PyFunc\n",
"## Serving LLMs with MLflow: Leveraging Custom PyFunc"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"<a href=\"https://raw.githubusercontent.com/mlflow/mlflow/master/docs/source/llms/custom-pyfunc-for-llms/notebooks/custom-pyfunc-advanced-llm.ipynb\" class=\"notebook-download-btn\">Download this Notebook</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"### Introduction\n",
"\n",
Expand Down
313 changes: 257 additions & 56 deletions docs/source/llms/transformers/guide/index.rst

Large diffs are not rendered by default.

171 changes: 62 additions & 109 deletions docs/source/llms/transformers/index.rst

Large diffs are not rendered by default.

Expand Up @@ -6,8 +6,20 @@
"source": [
"## Introduction to MLflow and OpenAI's Whisper\n",
"\n",
"Discover the integration of [OpenAI's Whisper](https://huggingface.co/openai), an [ASR system](https://en.wikipedia.org/wiki/Speech_recognition), with MLflow in this tutorial.\n",
"\n",
"Discover the integration of [OpenAI's Whisper](https://huggingface.co/openai), an [ASR system](https://en.wikipedia.org/wiki/Speech_recognition), with MLflow in this tutorial.\n"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"<a href=\"https://raw.githubusercontent.com/mlflow/mlflow/master/docs/source/llms/transformers/tutorials/audio-transcription/whisper.ipynb\" class=\"notebook-download-btn\">Download this Notebook</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### What You Will Learn in This Tutorial\n",
"\n",
"- Establish an audio transcription **pipeline** using the Whisper model.\n",
Expand Down Expand Up @@ -333,6 +345,10 @@
" signature=signature,\n",
" input_example=audio,\n",
" model_config=model_config,\n",
" # Since MLflow 2.11.0, you can save the model in 'reference-only' mode to reduce storage usage by not saving\n",
" # the base model weights but only the reference to the HuggingFace model hub. To enable this, uncomment the\n",
" # following line:\n",
" # save_pretrained=False,\n",
" )"
]
},
Expand Down
Expand Up @@ -6,7 +6,20 @@
"source": [
"## Introduction to Conversational AI with MLflow and DialoGPT\n",
"\n",
"Welcome to our tutorial on integrating [Microsoft's DialoGPT](https://huggingface.co/microsoft/DialoGPT-medium) with MLflow's transformers flavor to explore conversational AI.\n",
"Welcome to our tutorial on integrating [Microsoft's DialoGPT](https://huggingface.co/microsoft/DialoGPT-medium) with MLflow's transformers flavor to explore conversational AI."
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"<a href=\"https://raw.githubusercontent.com/mlflow/mlflow/master/docs/source/llms/transformers/tutorials/conversational/conversational-model.ipynb\" class=\"notebook-download-btn\">Download this Notebook</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"### Learning Objectives\n",
"\n",
Expand Down
Expand Up @@ -6,8 +6,20 @@
"source": [
"## Fine-Tuning Transformers with MLflow for Enhanced Model Management\n",
"\n",
"Welcome to our in-depth tutorial on fine-tuning Transformers models with enhanced management using MLflow.\n",
"\n",
"Welcome to our in-depth tutorial on fine-tuning Transformers models with enhanced management using MLflow."
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"<a href=\"https://raw.githubusercontent.com/mlflow/mlflow/master/docs/source/llms/transformers/tutorials/fine-tuning/transformers-fine-tuning.ipynb\" class=\"notebook-download-btn\">Download the Fine Tuning Notebook</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### What You Will Learn in This Tutorial\n",
"\n",
"- Understand the process of fine-tuning a Transformers model.\n",
Expand Down
Expand Up @@ -6,8 +6,20 @@
"source": [
"## Prompt Templating with MLflow and Transformers\n",
"\n",
"Welcome to our in-depth tutorial on using prompt templates to conveniently customize the behavior of Transformers pipelines using MLflow. \n",
"\n",
"Welcome to our in-depth tutorial on using prompt templates to conveniently customize the behavior of Transformers pipelines using MLflow. "
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"<a href=\"https://raw.githubusercontent.com/mlflow/mlflow/master/docs/source/llms/transformers/tutorials/prompt-templating/prompt-templating.ipynb\" class=\"notebook-download-btn\">Download this Notebook</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Learning Objectives\n",
"\n",
"In this tutorial, you will:\n",
Expand Down Expand Up @@ -233,6 +245,10 @@
" signature=signature,\n",
" input_example=\"Tell me the largest bird\",\n",
" prompt_template=prompt_template,\n",
" # Since MLflow 2.11.0, you can save the model in 'reference-only' mode to reduce storage usage by not saving\n",
" # the base model weights but only the reference to the HuggingFace model hub. To enable this, uncomment the\n",
" # following line:\n",
" # save_pretrained=False,\n",
" )"
]
},
Expand Down
Expand Up @@ -6,8 +6,20 @@
"source": [
"## Introduction to MLflow and Transformers\n",
"\n",
"Welcome to our tutorial on leveraging the power of **Transformers** with **MLflow**. This guide is designed for beginners, focusing on machine learning workflows and model management.\n",
"\n",
"Welcome to our tutorial on leveraging the power of **Transformers** with **MLflow**. This guide is designed for beginners, focusing on machine learning workflows and model management.\n"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"<a href=\"https://raw.githubusercontent.com/mlflow/mlflow/master/docs/source/llms/transformers/tutorials/text-generation/text-generation.ipynb\" class=\"notebook-download-btn\">Download this Notebook</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### What Will You Learn?\n",
"\n",
"In this tutorial, you will learn how to:\n",
Expand Down Expand Up @@ -234,7 +246,14 @@
"\n",
"When logging the model, crucial metadata such as the model's signature, which was previously established, is included. This metadata plays a significant role in the subsequent stages of the model's lifecycle, from tracking its evolution to facilitating its deployment in different environments. The signature, in particular, ensures the model's compatibility and consistent performance across various platforms, thereby enhancing its utility and reliability in practical applications.\n",
"\n",
"By logging our model in this way, we ensure that it is not only well-documented but also primed for future use, whether it be for further development, comparative analysis, or deployment."
"By logging our model in this way, we ensure that it is not only well-documented but also primed for future use, whether it be for further development, comparative analysis, or deployment.\n",
"\n",
"\n",
"#### A Tip for Saving Storage Cost\n",
"\n",
"When you call [mlflow.transformers.log_model](https://www.mlflow.org/docs/latest/python_api/mlflow.transformers.html#mlflow.transformers.log_model), MLflow will saves a full copy of the Transformers model weight. However, this could take large storage space (3GB for `flan-alpaca-large` model), but might be redundant when you don't modify the model weight, because it is exactly same as the one you can download from the HuggingFace model hub.\n",
"\n",
"To avoid the unnecessary copy, you can use 'reference-only' save mode which is introduced in MLflow 2.11.0, by setting ``save_pretrained=False`` when logging or saving the Transformer model. This tells MLflow not to save the copy of the base model weight, but just a reference to the HuggingFace Hub repository and version, hence more storage-efficient and faster in time. For more details about this feature, please refer to [Storage-Efficient Model Logging](https://www.mlflow.org/docs/latest/llms/transformers/guide/index.html#storage-efficient-model-logging-with-save-pretrained-option)."
]
},
{
Expand All @@ -249,6 +268,8 @@
" artifact_path=\"text_generator\",\n",
" input_example=input_example,\n",
" signature=signature,\n",
" # Uncomment the following line to save the model in 'reference-only' mode:\n",
" # save_pretrained=False,\n",
" )"
]
},
Expand Down
Expand Up @@ -6,8 +6,20 @@
"source": [
"## Introduction to Translation with Transformers and MLflow\n",
"\n",
"In this tutorial, we delve into the world of language translation by leveraging the power of [Transformers](https://huggingface.co/docs/transformers) and MLflow. This guide is crafted for practitioners with a grasp of machine learning concepts who seek to streamline their translation model workflows. We will showcase the use of MLflow to log, manage, and serve a cutting-edge translation model - the `google/flan-t5-base` from the [🤗 Hugging Face](https://huggingface.co/) library.\n",
"\n",
"In this tutorial, we delve into the world of language translation by leveraging the power of [Transformers](https://huggingface.co/docs/transformers) and MLflow. This guide is crafted for practitioners with a grasp of machine learning concepts who seek to streamline their translation model workflows. We will showcase the use of MLflow to log, manage, and serve a cutting-edge translation model - the `google/flan-t5-base` from the [🤗 Hugging Face](https://huggingface.co/) library."
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"<a href=\"https://raw.githubusercontent.com/mlflow/mlflow/master/docs/source/llms/transformers/tutorials/translation/component-translation.ipynb\" class=\"notebook-download-btn\">Download this Notebook</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Learning Objectives\n",
"\n",
"Throughout this tutorial, you will:\n",
Expand Down
12 changes: 8 additions & 4 deletions mlflow/utils/docstring_utils.py
Expand Up @@ -279,21 +279,25 @@ class that describes the model's inputs and outputs. If not specified but an
instead only saving the reference to the HuggingFace Hub model repository and its commit hash.
This is useful when you load the pretrained model from HuggingFace Hub and want to log or save
it to MLflow without modifying the model weights. In such case, specifying this flag to
``False`` will save the storage space and reduce time to save the model.
``False`` will save the storage space and reduce time to save the model. Please refer to the
:ref:`Storage-Efficient Model Logging <transformers-save-pretrained-guide>` for more detailed usage.
.. warning::
If the model is saved with ``save_pretrained`` set to ``False``, the model cannot be
registered to the MLflow Model Registry. In order to convert the model to the one that
can be registered, you can use mlflow.transformers.download_pretrained_model() to download
the model weights from the HuggingFace Hub and save it in the existing model artifacts.
can be registered, you can use :py:func:`mlflow.transformers.persist_pretrained_model()`
to download the model weights from the HuggingFace Hub and save it in the existing model
artifacts. Please refer to :ref:`Transformers flavor documentation <persist-pretrained-guide>`
for more detailed usage.
.. code-block:: python
import mlflow.transformers
model_uri = "YOUR_MODEL_URI_LOGGED_WITH_SAVE_PRETRAINED_FALSE"
model = mlflow.transformers.download_pretrained_model(model_uri)
model = mlflow.transformers.persist_pretrained_model(model_uri)
mlflow.register_model(model_uri, "model_name")
.. important::
Expand Down
1 change: 1 addition & 0 deletions mlflow/utils/logging_utils.py
Expand Up @@ -90,6 +90,7 @@ def _configure_mlflow_loggers(root_module_name):
def eprint(*args, **kwargs):
print(*args, file=MLFLOW_LOGGING_STREAM, **kwargs)


class LoggerMessageFilter(logging.Filter):
def __init__(self, module: str, filter_regex: re.Pattern):
super().__init__()
Expand Down
2 changes: 1 addition & 1 deletion tests/transformers/test_transformers_model_export.py
Expand Up @@ -4,8 +4,8 @@
import json
import os
import pathlib
import shutil
import re
import shutil
import textwrap
from pathlib import Path
from unittest import mock
Expand Down

0 comments on commit b8561ee

Please sign in to comment.