<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article Distributed Fine Tuning of LLMs on Databricks Lakehouse with Ray AI Runtime, Part 1 in Technical Blog</title>
    <link>https://community.databricks.com/t5/technical-blog/distributed-fine-tuning-of-llms-on-databricks-lakehouse-with-ray/ba-p/38259</link>
    <description>&lt;P data-unlink="true"&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;EM&gt;Authors:&amp;nbsp;&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;Anastasia Prokaieva&amp;nbsp;and Puneet Jain&amp;nbsp;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;The aim of this blog is to show the end-to-end process of conversion from vanilla Hugging Face &lt;/FONT&gt;&lt;span class="lia-unicode-emoji" title=":hugging_face:"&gt;🤗&lt;/span&gt;&amp;nbsp;&lt;FONT face="book antiqua,palatino"&gt;to &lt;A href="https://docs.ray.io/en/latest/ray-air/getting-started.html" target="_blank" rel="noopener"&gt;Ray AIR&lt;/A&gt; &lt;/FONT&gt;&lt;span class="lia-unicode-emoji" title=":hugging_face:"&gt;🤗&lt;/span&gt;&amp;nbsp;&lt;FONT face="book antiqua,palatino"&gt;on Databricks, without changing the training logic unless necessary. We have seen many customers struggling with fine-tuning their LLM on smaller GPU instances such as &lt;A href="https://www.nvidia.com/en-us/data-center/products/a10-gpu/" target="_blank" rel="noopener"&gt;A10&lt;/A&gt; or &lt;A href="https://www.nvidia.com/en-us/data-center/v100/" target="_blank" rel="noopener"&gt;V100&lt;/A&gt;, and so we decided to release this example using the most commonly available GPU instances across all regions on Databricks, without using the A100 instance type.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Within this blog we going to cover:&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Set up Ray Spark on Databricks&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Load data from Delta into the Hugging Face data loader&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Set your preprocess with Ray AIR&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Run distributed training with Ray AIR&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;How to use Ray Dashboard&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Databricks &lt;A href="https://www.databricks.com/blog/2023/02/28/announcing-ray-support-databricks-and-apache-spark-clusters.html" target="_blank" rel="noopener"&gt;announced support for Ray on the Apache Spark cluster recently this year&lt;/A&gt;&amp;nbsp;- a prominent compute framework for running scalable AI and Python workloads in order to dramatically simplify model development across both platforms.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;A href="https://docs.ray.io/en/latest/ray-air/getting-started.html" target="_blank" rel="noopener"&gt;Ray AI Runtime&lt;/A&gt; (AIR) is a scalable and unified toolkit for ML applications. AIR enables simple scaling of individual workloads, end-to-end workflows, and popular ecosystem frameworks. Ray AIR aims to simplify the ecosystem of machine learning frameworks, platforms, and tools. One of the reasons we have selected Ray AIR for this task on top seamless integration with Apache Spark on Databricks but also because it’s fully open-source and it enables swapping between popular frameworks which is very important for Deep Learning users while switching between PyTorch and Hugging Face.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="AnastasiProk_0-1690188188156.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2958i90240D7FA50A9F7D/image-size/large?v=v2&amp;amp;px=999" role="button" title="AnastasiProk_0-1690188188156.png" alt="AnastasiProk_0-1690188188156.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-align-center"&gt;&lt;EM&gt;&lt;FONT face="book antiqua,palatino"&gt;AIR provides a unified API for the ML ecosystem. This diagram shows how AIR enables an ecosystem of libraries to be run at scale in just a few lines of code.&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;The reason for choosing Ray AIR is that it is playing a role of a wrapper between various frameworks, which allows users simply move from one approach to another. You’ll see in part 3 of this series, we are going to fine-tune Pythia12B and Falcon7B without changing our main code from fine-tuning BERT or Roberta models, and we would just add new configuration files and parameters.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;This simplicity was one of the reasons we decided to use Ray AIR. Something to keep in mind, the same training could be done without using Ray or RayAIR, such as using native &lt;A href="https://pytorch.org/tutorials/intermediate/ddp_tutorial.html" target="_blank" rel="noopener"&gt;PyTorch DDP&lt;/A&gt; or &lt;A href="https://pytorch.org/docs/stable/fsdp.html" target="_blank" rel="noopener"&gt;FSDP&lt;/A&gt; capabilities or using &lt;A href="https://huggingface.co/docs/accelerate/index" target="_blank" rel="noopener"&gt;Accelerate from Hugging Face&lt;/A&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;H3&gt;&lt;FONT face="book antiqua,palatino"&gt;Use cases&amp;nbsp;&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;For this blog we have selected 2 datasets and 2 models to demonstrate the simplicity and flexibility that RayAIR brings when we are trying to find the best model for a use case.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;In Part 1 of the series, we are going to focus on the 2 most common use cases - Sequence Classification (simply known as Classification) and Token Classification(known as Named Entity Recognition) - the difference between both is that you require to classify the classification of the whole corpus that passed to the model(e.g. you want to know a sentiment of a tweet &amp;lt;The XX has broken again rules&amp;gt;, would become &amp;lt;negative&amp;gt;), or you required to classify token(e.g. &amp;lt;Anna is going to the Los Angeles California&amp;gt; might be mapped into&amp;lt;I-PER, O, I-LOC, I-LOC, I-LOC &amp;gt;, etc and they can be later classified as well, for example, check more about NER naming convention &lt;A href="https://en.wikipedia.org/wiki/Inside%E2%80%93outside%E2%80%93beginning_(tagging)" target="_blank" rel="noopener"&gt;here&lt;/A&gt;) inside the corpus. If you have your own tags for the token, this is not a problem, you would need to adapt your tokenizer, &lt;A href="https://huggingface.co/learn/nlp-course/chapter6/2" target="_blank" rel="noopener"&gt;here&lt;/A&gt; you can find an example and a class from the HF.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;For this series, we’ve selected 2 popular datasets from Hugging Face with descriptions given below:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;A href="https://huggingface.co/datasets/conll2003" target="_blank" rel="noopener"&gt;CoNLL-2003&lt;/A&gt; is a widely used dataset and evaluation benchmark in the field of natural language processing (NLP) and named entity recognition (NER). The data is a collection of news wire articles from the &lt;A href="http://trec.nist.gov/data/reuters/reuters.html" target="_blank" rel="noopener"&gt;Reuters Corpus&lt;/A&gt;. The annotation has been done by people of the University of Antwerp. It focuses on four types of named entities: persons, locations, organizations, and names of miscellaneous entities that do not belong to the previous three groups. Below is an example of the format:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 12.15.57.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2971iAF4C1469D5B07FC4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 12.15.57.png" alt="Screenshot 2023-07-25 at 12.15.57.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;A href="https://huggingface.co/datasets/glue/viewer/cola/train" target="_blank" rel="noopener"&gt;The CoLA (Corpus of Linguistic Acceptability)&lt;/A&gt; dataset consists of English sentences labeled for grammatical acceptability. Each sentence is annotated with a binary label indicating whether it is linguistically acceptable or not. It forms one of the tasks used in the &lt;A href="https://gluebenchmark.com/" target="_blank" rel="noopener"&gt;GLUE Benchmark&lt;/A&gt;. Here is an example of the cola format:&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 12.16.07.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2972i14AE7DAE9DC4A869/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 12.16.07.png" alt="Screenshot 2023-07-25 at 12.16.07.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;H2&gt;&lt;FONT face="book antiqua,palatino"&gt;Let’s begin&amp;nbsp;&lt;/FONT&gt;&lt;/H2&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Before even starting loading your dataset we need to install a few libraries and set our Ray cluster. Here we are using Databricks 13.1 ML runtime, where we already have a new version of the &lt;A href="https://www.databricks.com/blog/2023/04/18/introducing-mlflow-23-enhanced-native-llm-support-and-new-features.html" target="_blank" rel="noopener"&gt;MLFlow 2.3 that has a new Transformer Flavor&lt;/A&gt;.&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;If you are using a DBR ML runtime lower than 13.1&amp;nbsp; you will have to install MLFlow 2.3 as well:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 12.24.47.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2973i83648AE744D95AF8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 12.24.47.png" alt="Screenshot 2023-07-25 at 12.24.47.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Other libraries are already preinstalled on the Databricks Machine Learning cluster, so you would not have to install them.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;H3&gt;&lt;FONT face="book antiqua,palatino"&gt;Setting Ray&amp;nbsp;&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;In order to set up a Ray cluster on Databricks after the full integration of Ray on top of Spark on the platform you would need only a few tiny things:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Set a few variables such as num_cpu_cores_per_worker and num_gpu_per_worker&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Run an init function from Ray to set up a Ray Cluster&amp;nbsp;&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 12.25.34.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2974iFE7E8609D062643D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 12.25.34.png" alt="Screenshot 2023-07-25 at 12.25.34.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Once run you will have the following prompt appearing: &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="book antiqua,palatino"&gt;After the function finishes running it will show a link to open ray the dashboard (see the highlighted hyperlink on the image below):&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="AnastasiProk_3-1690189541140.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2961i56AEAED413D12965/image-size/large?v=v2&amp;amp;px=999" role="button" title="AnastasiProk_3-1690189541140.png" alt="AnastasiProk_3-1690189541140.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-align-center"&gt;&lt;EM&gt;&lt;FONT face="book antiqua,palatino"&gt;Output within a Notebook cell once the Ray was initiated and the link to the Interactive Dashboard is given&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;And you are set to go!&lt;/FONT&gt;&lt;/P&gt;&lt;H2&gt;&lt;FONT face="book antiqua,palatino"&gt;Loading and preprocessing data&amp;nbsp;&lt;/FONT&gt;&lt;/H2&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="AnastasiProk_0-1690190438217.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2962iDEE7DA1E7B6505C1/image-size/large?v=v2&amp;amp;px=999" role="button" title="AnastasiProk_0-1690190438217.png" alt="AnastasiProk_0-1690190438217.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-align-center"&gt;&lt;EM&gt;&lt;FONT face="book antiqua,palatino"&gt;Typical LLM Pipeline example&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;In order to apply any LLM model to your own data you would need to follow the following steps:&lt;/FONT&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Load your original data&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Clean if necessary&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Apply a tokenizer to your data&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Apply a pre-trained model to your data&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Apply post-processing if required&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;All those steps can be incorporated into a single pipeline, Hugging Face offers Pipelines for inference. But why we are talking about inference before even training? Because you still need to apply pre-processing steps before fine-tuning a model on your data. For the classification use case, the dataset is ready to be consumed but for the Token Classification, we had to apply a transformation in order to correctly associate tokenized input data with its original tokens. We attach a script under utils that helps you to properly do that.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;There are multiple options on how to read data, we are going to talk about the two most common options from Delta and directly from the HF Datasets.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;H3&gt;&lt;FONT face="book antiqua,palatino"&gt;From Delta&amp;nbsp;&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;A href="https://www.databricks.com/blog/contributing-spark-loader-for-hugging-face-datasets" target="_blank" rel="noopener"&gt;Hugging Face gets first-class Spark support&lt;/A&gt; has been recently announced. This allows users to use Spark to efficiently load and transform data for training or fine-tuning a model, then easily map their Spark dataframe into a Hugging Face dataset for super simple integration into a training pipeline. This combines cost savings and speed from Spark and optimizations like memory mapping and smart caching from Hugging Face datasets.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 13.10.21.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2994iC6FA3BBA78CF4700/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 13.10.21.png" alt="Screenshot 2023-07-25 at 13.10.21.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;H3&gt;&lt;FONT face="book antiqua,palatino"&gt;&amp;nbsp;From memory&amp;nbsp;&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Let’s say you are getting your data from the Hugging Face Hub or somewhere else, this would be downloaded directly into your Disk, and will be available while your Cluster is on (you can, of course, download it and store on the DBFS and load it back into the memory back). The same could work with reading your files from Parquet or with the deltaRay incubator project. Here we are showing how to read from a list of parquet files:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 13.10.07.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2993i5C20583358479A85/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 13.10.07.png" alt="Screenshot 2023-07-25 at 13.10.07.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;H3&gt;&lt;FONT face="book antiqua,palatino"&gt;&amp;nbsp;Training and Scoring&amp;nbsp;&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;In order to fine-tune your model from HF you would need to construct a Trainer and it usually contains the model, arguments(parameters) you want to train your model with, and a tokenizer that will create embeddings corresponding to the family of the model, metrics you want to evaluate your model on and input data.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Keep in my that it’s recommended to not mix tokenizers(embeddings) from different family models because they vary. Your compute metrics are often better to take from a dataset that corresponds to your use cases from the HF Hub.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 13.09.48.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2992iD5A65E1611547EAC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 13.09.48.png" alt="Screenshot 2023-07-25 at 13.09.48.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Now let’s talk a bit more about the Arguments to train your model with, there are various ways to pass your arguments to the HF Trainer. Here we are using a Python data class to create our default parameters and placing them in an external Python file.&amp;nbsp;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 12.30.24.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2976iDB86D31F77E5A1BA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 12.30.24.png" alt="Screenshot 2023-07-25 at 12.30.24.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&amp;nbsp;It’s very simple to use those arguments later on. First of all, HF has a HfArgumentParser that you can read and pass directly to the HF Trainer&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 13.08.42.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2991i96F9728361FB134F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 13.08.42.png" alt="Screenshot 2023-07-25 at 13.08.42.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT face="book antiqua,palatino"&gt;Another way of doing this would be to directly read the ScriptArguments class and convert it into a dictionary("dict") and pass your preselected arguments to the trainer.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 13.07.59.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2990iD5D1E03F209FD70F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 13.07.59.png" alt="Screenshot 2023-07-25 at 13.07.59.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;H3&gt;&lt;FONT face="book antiqua,palatino"&gt;Config for HF Trainer with RayAIR&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Let’s talk about the configuration file for the Hugging Face Trainer Class, that Ray AIR inherits within HuggingFaceTrainer, we are not going to talk about each of the parameters used during the training but will pay attention to some new configurations that you would not have seen yet.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2023-07-25 at 12.11.13.png" style="width: 702px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2969i604D3F91D126DAFA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-07-25 at 12.11.13.png" alt="Screenshot 2023-07-25 at 12.11.13.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;When you set everything the trainer is evoked you can go and check your GPU utilization under the Ray Dashboard(the link to the dashboard is given when you first run setup_ray_cluster. Ray Dashboard is interactive so you will be able to monitor your resource usage in almost real-time. This can help to understand whether your cluster configuration is sufficient or not and to properly catch OOM on your GPU and CPU.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="AnastasiProk_0-1690276178329.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2965i46D901798B58E19C/image-size/large?v=v2&amp;amp;px=999" role="button" title="AnastasiProk_0-1690276178329.png" alt="AnastasiProk_0-1690276178329.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-align-center"&gt;&lt;EM&gt;&lt;FONT face="book antiqua,palatino"&gt;Ray Dashboard Cluster Tab, while the model training is enabled.&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Above you have an example of a Ray Dashboard with the GPU usage while we were training, you have a similar capability starting from DBR 13.2 ML under your cluster configuration go to the Metrics Page.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;H3&gt;&lt;FONT face="book antiqua,palatino"&gt;Checkpoints&amp;nbsp;&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;After the trainer is finished it’s very simple to get your results back, they will be all under the checkpoint folder you’ve provided. Sometimes it may happen that your notebook has crashed and your result variable is gone, but if your cluster is still on, your checkpoints are alive! Here is an example of what contains a checkpoint(everything you need to put your model in production):&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="AnastasiProk_1-1690276228595.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2966iC5C3ED81CFB41BE0/image-size/large?v=v2&amp;amp;px=999" role="button" title="AnastasiProk_1-1690276228595.png" alt="AnastasiProk_1-1690276228595.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="AnastasiProk_2-1690276228538.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2967i9DAB63E18146DF5F/image-size/large?v=v2&amp;amp;px=999" role="button" title="AnastasiProk_2-1690276228538.png" alt="AnastasiProk_2-1690276228538.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;FONT face="book antiqua,palatino"&gt;You also have events logged if you want to use a TensorBoard.&lt;/FONT&gt;&lt;/P&gt;&lt;H3&gt;&lt;FONT face="book antiqua,palatino"&gt;Conclusions&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;In this first part, we have demonstrated to you how to load your data from Delta Lake or from the memory and use your datasets to fine-tune a Huggig Face model using the RayAIR framework and Apache Spark. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;If you liked this blog please check this &lt;A href="https://github.com/AnastasiaProkaieva/llm-databricks-rayair" target="_self"&gt;Git Repository&lt;/A&gt; with the code that supports this series of blogs.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;The next part will cover how to:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Track and log your LLM with MLFlow&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Predict on test data with Ray AIR&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Serve your model with Real-Time Endpoint on Databricks using CPU and GPU!&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="book antiqua,palatino"&gt;Talk about issues we encountered and solutions we found&amp;nbsp;&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;See you soon!&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2023 14:42:43 GMT</pubDate>
    <dc:creator>AnastasiProk</dc:creator>
    <dc:date>2023-09-06T14:42:43Z</dc:date>
    <item>
      <title>Distributed Fine Tuning of LLMs on Databricks Lakehouse with Ray AI Runtime, Part 1</title>
      <link>https://community.databricks.com/t5/technical-blog/distributed-fine-tuning-of-llms-on-databricks-lakehouse-with-ray/ba-p/38259</link>
      <description>&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="AnastasiProk_0-1690188188156.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2958i90240D7FA50A9F7D/image-size/large?v=v2&amp;amp;px=999" role="button" title="AnastasiProk_0-1690188188156.png" alt="AnastasiProk_0-1690188188156.png" /&gt;&lt;/span&gt;Following the previous series of blog posts published by Databricks (&lt;/SPAN&gt;&lt;A href="https://www.databricks.com/blog/2023/03/20/fine-tuning-large-language-models-hugging-face-and-deepspeed.html" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Running DeepSpeed on Databricks&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;A href="https://www.databricks.com/blog/2023/02/06/getting-started-nlp-using-hugging-face-transformers-pipelines.html"&gt;&lt;SPAN&gt;FineTunning with HF&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;) around LLMs and recent announcements about open-sourced LLMs such as DollyV2, Falcon40B, MPT7B, etc. for commercial usage - have exploded the interest in training your own LLM. There are a plethora of tools that can help you to accelerate your data preprocessing, data loading, model training, scoring and finally serving, but they are still spread across various platforms and people are struggling to understand why model X fit perfectly fine but model Z&amp;nbsp; is causing out of memory and what to do with that. We also often hear that FineTuning takes a significant amount of time, and people want to accelerate training but also inference, and they want to do that seamlessly and coherently without changing their code significantly while moving from one model to another.&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;SPAN&gt;Here we continue this series of blog posts around scaling fine-tuning and scoring the LLM models. This time we are going to use Ray AI Runtime(AIR) for the series of blog posts about how to tune various Large Language Models(LLM’s) on the Databricks Lakehouse Platform from BERT to MPT7B or even LLAMA70B.&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;SPAN&gt;In the first few parts of the series, we are going to fine-tune a few models: the BERT Large model for classical multi-label classification use cases and another one for the Multilingual Named Entity Recognition (Token Classification) model both from the Hugging Face &lt;span class="lia-unicode-emoji" title=":hugging_face:"&gt;🤗&lt;/span&gt; Hub on the Databricks Lakhouse Platform, - simply staying “relatively” small models(up to a billion parameters). Our last part will go deeper into scaling LLMs with more than 12B and higher parameters.&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;&lt;SPAN&gt;We have tried to make our example model’s family agnostic, and we will specify within the blog when and where you would require to customize your code accordingly.&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 14:42:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/distributed-fine-tuning-of-llms-on-databricks-lakehouse-with-ray/ba-p/38259</guid>
      <dc:creator>AnastasiProk</dc:creator>
      <dc:date>2023-09-06T14:42:43Z</dc:date>
    </item>
  </channel>
</rss>

