diff --git a/configs/image_classification/local.yml b/configs/image_classification/local.yml index 5d04f88332..a701c16899 100644 --- a/configs/image_classification/local.yml +++ b/configs/image_classification/local.yml @@ -10,7 +10,7 @@ data: valid_split: null column_mapping: image_column: image - target_column: labels + target_column: label params: epochs: 2 diff --git a/configs/llm_finetuning/qwen.yml b/configs/llm_finetuning/qwen.yml new file mode 100644 index 0000000000..590feea34f --- /dev/null +++ b/configs/llm_finetuning/qwen.yml @@ -0,0 +1,34 @@ +task: llm-sft +base_model: Qwen/Qwen2.5-Coder-7B-Instruct +project_name: autotrain-qwen-finetune +log: tensorboard +backend: local + +data: + path: HuggingFaceH4/no_robots + train_split: test + valid_split: null + chat_template: tokenizer + column_mapping: + text_column: messages + +params: + block_size: 2048 + model_max_length: 4096 + epochs: 1 + batch_size: 1 + lr: 1e-5 + peft: true + quantization: int4 + target_modules: all-linear + padding: right + optimizer: adamw_torch + scheduler: cosine + gradient_accumulation: 1 + mixed_precision: fp16 + merge_adapter: true + +hub: + username: ${HF_USERNAME} + token: ${HF_TOKEN} + push_to_hub: true diff --git a/docs/source/_toctree.yml b/docs/source/_toctree.yml index d8af74d4b1..3e74d4086b 100644 --- a/docs/source/_toctree.yml +++ b/docs/source/_toctree.yml @@ -10,20 +10,12 @@ title: Getting Started - sections: - local: quickstart_spaces - title: Quickstart - title: AutoTrain on Hugging Face Spaces -- sections: + title: Train on Spaces - local: quickstart - title: Quickstart + title: Train Locally - local: config - title: Configurations - title: Use AutoTrain Locally -- sections: - - local: col_map - title: Understanding Column Mapping - - local: autotrain_api - title: AutoTrain API - title: Miscellaneous + title: Config File + title: Quickstart - sections: - local: tasks/llm_finetuning title: LLM Finetuning @@ -33,10 +25,8 @@ title: Extractive QA - local: tasks/sentence_transformer title: Sentence Transformer - - local: tasks/image_classification - title: Image Classification - - local: tasks/image_regression - title: Image Scoring/Regression + - local: tasks/image_classification_regression + title: Image Classification / Regression - local: tasks/object_detection title: Object Detection - local: tasks/dreambooth @@ -49,20 +39,8 @@ title: Tabular title: Tasks - sections: - - local: params/extractive_qa_params - title: Extractive QA - - local: params/image_classification_params - title: Image Classification - - local: params/image_regression_params - title: Image Scoring/Regression - - local: params/object_detection_params - title: Object Detection - - local: params/dreambooth_params - title: DreamBooth - - local: params/seq2seq_params - title: Seq2Seq - - local: params/token_classification_params - title: Token Classification - - local: params/tabular_params - title: Tabular - title: Parameters \ No newline at end of file + - local: col_map + title: Understanding Column Mapping + - local: autotrain_api + title: AutoTrain API + title: Miscellaneous \ No newline at end of file diff --git a/docs/source/index.mdx b/docs/source/index.mdx index 0359470a1f..bd618508a6 100644 --- a/docs/source/index.mdx +++ b/docs/source/index.mdx @@ -1,4 +1,4 @@ -# What is AutoTrain Advanced? +# AutoTrain ![autotrain-homepage](https://raw.githubusercontent.com/huggingface/autotrain-advanced/main/static/autotrain_homepage.png) diff --git a/docs/source/params/dreambooth_params.mdx b/docs/source/params/dreambooth_params.mdx deleted file mode 100644 index 0c0056d2b4..0000000000 --- a/docs/source/params/dreambooth_params.mdx +++ /dev/null @@ -1,3 +0,0 @@ -# DreamBooth Parameters - -[[autodoc]] trainers.dreambooth.params.DreamBoothTrainingParams \ No newline at end of file diff --git a/docs/source/params/extractive_qa_params.mdx b/docs/source/params/extractive_qa_params.mdx deleted file mode 100644 index de8e18871a..0000000000 --- a/docs/source/params/extractive_qa_params.mdx +++ /dev/null @@ -1,3 +0,0 @@ -# Extractive Question Answering Parameters - -[[autodoc]] trainers.extractive_question_answering.params.ExtractiveQuestionAnsweringParams \ No newline at end of file diff --git a/docs/source/params/image_classification_params.mdx b/docs/source/params/image_classification_params.mdx deleted file mode 100644 index 55eebd8914..0000000000 --- a/docs/source/params/image_classification_params.mdx +++ /dev/null @@ -1,3 +0,0 @@ -# Image Classification Parameters - -[[autodoc]] trainers.image_classification.params.ImageClassificationParams \ No newline at end of file diff --git a/docs/source/params/image_regression_params.mdx b/docs/source/params/image_regression_params.mdx deleted file mode 100644 index 8a94f41e68..0000000000 --- a/docs/source/params/image_regression_params.mdx +++ /dev/null @@ -1,5 +0,0 @@ -# Image Scoring/Regression Parameters - -The Parameters for image scoring/regression are same as the parameters for image classification. - -[[autodoc]] trainers.image_regression.params.ImageRegressionParams \ No newline at end of file diff --git a/docs/source/params/object_detection_params.mdx b/docs/source/params/object_detection_params.mdx deleted file mode 100644 index 59cee7acad..0000000000 --- a/docs/source/params/object_detection_params.mdx +++ /dev/null @@ -1,3 +0,0 @@ -# Object Detection Parameters - -[[autodoc]] trainers.object_detection.params.ObjectDetectionParams diff --git a/docs/source/params/seq2seq_params.mdx b/docs/source/params/seq2seq_params.mdx deleted file mode 100644 index 82754114bf..0000000000 --- a/docs/source/params/seq2seq_params.mdx +++ /dev/null @@ -1,3 +0,0 @@ -# Seq2Seq Parameters - -[[autodoc]] trainers.seq2seq.params.Seq2SeqParams diff --git a/docs/source/params/tabular_params.mdx b/docs/source/params/tabular_params.mdx deleted file mode 100644 index c99608bd58..0000000000 --- a/docs/source/params/tabular_params.mdx +++ /dev/null @@ -1,3 +0,0 @@ -# Tabular Parameters - -[[autodoc]] trainers.tabular.params.TabularParams diff --git a/docs/source/params/token_classification_params.mdx b/docs/source/params/token_classification_params.mdx deleted file mode 100644 index 00fc66b18b..0000000000 --- a/docs/source/params/token_classification_params.mdx +++ /dev/null @@ -1,3 +0,0 @@ -# Token Classification Parameters - -[[autodoc]] trainers.token_classification.params.TokenClassificationParams diff --git a/docs/source/tasks/dreambooth.mdx b/docs/source/tasks/dreambooth.mdx index 9c5321567e..f8402a9ed8 100644 --- a/docs/source/tasks/dreambooth.mdx +++ b/docs/source/tasks/dreambooth.mdx @@ -33,3 +33,8 @@ This token acts as a unique identifier for your subject within the model. Typically, you will use a simple, descriptive keyword like prompt in the parameters section of your training setup. This token will be used to generate new images of your subject by the model. + + +## Parameters + +[[autodoc]] trainers.dreambooth.params.DreamBoothTrainingParams \ No newline at end of file diff --git a/docs/source/tasks/extractive_qa.mdx b/docs/source/tasks/extractive_qa.mdx index e340b97bed..5a303e1a4b 100644 --- a/docs/source/tasks/extractive_qa.mdx +++ b/docs/source/tasks/extractive_qa.mdx @@ -28,4 +28,59 @@ Note: the preferred format for question answering is JSONL, if you want to use C Example dataset from Hugging Face Hub: [lhoestq/squad](https://huggingface.co/datasets/lhoestq/squad) -P.S. You can use both squad and squad v2 data format with correct column mappings. \ No newline at end of file +P.S. You can use both squad and squad v2 data format with correct column mappings. + +## Training Locally + +To train an Extractive QA model locally, you need a config file: + +```yaml +task: extractive-qa +base_model: google-bert/bert-base-uncased +project_name: autotrain-bert-ex-qa1 +log: tensorboard +backend: local + +data: + path: lhoestq/squad + train_split: train + valid_split: validation + column_mapping: + text_column: context + question_column: question + answer_column: answers + +params: + max_seq_length: 512 + max_doc_stride: 128 + epochs: 3 + batch_size: 4 + lr: 2e-5 + optimizer: adamw_torch + scheduler: linear + gradient_accumulation: 1 + mixed_precision: fp16 + +hub: + username: ${HF_USERNAME} + token: ${HF_TOKEN} + push_to_hub: true +``` + +To train the model, run the following command: + +```bash +$ autotrain --config config.yaml +``` + +Here, we are training a BERT model on the SQuAD dataset using the Extractive QA task. The model is trained for 3 epochs with a batch size of 4 and a learning rate of 2e-5. The training process is logged using TensorBoard. The model is trained locally and pushed to the Hugging Face Hub after training. + +## Training on the Hugging Face Spaces + +![AutoTrain Extractive Question Answering on Hugging Face Spaces](https://raw.githubusercontent.com/huggingface/autotrain-advanced/main/static/ext_qa.png) + +As always, pay special attention to column mapping. + +## Parameters + +[[autodoc]] trainers.extractive_question_answering.params.ExtractiveQuestionAnsweringParams \ No newline at end of file diff --git a/docs/source/tasks/image_classification.mdx b/docs/source/tasks/image_classification.mdx deleted file mode 100644 index 8bcf8a8034..0000000000 --- a/docs/source/tasks/image_classification.mdx +++ /dev/null @@ -1,63 +0,0 @@ -# Image Classification - -Image classification is a form of supervised learning where a model is trained to identify -and categorize objects within images. AutoTrain simplifies the process, enabling you to -train a state-of-the-art image classification model by simply uploading labeled example -images. - - -## Preparing your data - -To ensure your image classification model trains effectively, follow these guidelines for preparing your data: - - -### Organizing Images - - -Prepare a zip file containing your categorized images. Each category should have its own -subfolder named after the class it represents. For example, to differentiate between -'cats' and 'dogs', your zip file structure should resemble the following: - - -``` -cats_and_dogs.zip -├── cats -│ ├── cat.1.jpg -│ ├── cat.2.jpg -│ ├── cat.3.jpg -│ └── ... -└── dogs - ├── dog.1.jpg - ├── dog.2.jpg - ├── dog.3.jpg - └── ... -``` - -### Image Requirements - -- Format: Ensure all images are in JPEG, JPG, or PNG format. - -- Quantity: Include at least 5 images per class to provide the model with sufficient examples for learning. - -- Exclusivity: The zip file should exclusively contain folders named after the classes, -and these folders should only contain relevant images. No additional files or nested -folders should be included. - - -** Additional Tips** - -- Uniformity: While not required, having images of similar sizes and resolutions can help improve model performance. - -- Variability: Include a variety of images for each class to encompass the range of -appearances and contexts the model might encounter in real-world scenarios. - -Some points to keep in mind: - -- The zip file should contain multiple folders (the classes), each folder should contain images of a single class. -- The name of the folder should be the name of the class. -- The images must be jpeg, jpg or png. -- There should be at least 5 images per class. -- There must not be any other files in the zip file. -- There must not be any other folders inside the zip folder. - -When train.zip is decompressed, it creates two folders: cats and dogs. these are the two categories for classification. The images for both categories are in their respective folders. You can have as many categories as you want. \ No newline at end of file diff --git a/docs/source/tasks/image_classification_regression.mdx b/docs/source/tasks/image_classification_regression.mdx new file mode 100644 index 0000000000..97d892727a --- /dev/null +++ b/docs/source/tasks/image_classification_regression.mdx @@ -0,0 +1,247 @@ +# Image Classification & Regression + +Image classification is a form of supervised learning where a model is trained to identify +and categorize objects within images. AutoTrain simplifies the process, enabling you to +train a state-of-the-art image classification model by simply uploading labeled example +images. + +Image regression/scoring is a form of supervised learning where a model is trained to predict a +score or value for an image. AutoTrain simplifies the process, enabling you to train a +state-of-the-art image scoring model by simply uploading labeled example images. + + +## Preparing your data + +To ensure your image classification model trains effectively, follow these guidelines for preparing your data: + + +### Organizing Images For Image Classification + + +Prepare a zip file containing your categorized images. Each category should have its own +subfolder named after the class it represents. For example, to differentiate between +'cats' and 'dogs', your zip file structure should resemble the following: + + +``` +cats_and_dogs.zip +├── cats +│ ├── cat.1.jpg +│ ├── cat.2.jpg +│ ├── cat.3.jpg +│ └── ... +└── dogs + ├── dog.1.jpg + ├── dog.2.jpg + ├── dog.3.jpg + └── ... +``` + +You can also use a dataset from the Hugging Face Hub. Example dataset from Hugging Face Hub: [truepositive/hotdog_nothotdog](https://huggingface.co/datasets/truepositive/hotdog_nothotdog). + + +### Organizing Images for Image Regression/Scoring + + +Prepare a zip file containing your images and metadata.jsonl. + + +``` +Archive.zip +├── 0001.png +├── 0002.png +├── 0003.png +├── . +├── . +├── . +└── metadata.jsonl +``` + +Example for `metadata.jsonl`: + +``` +{"file_name": "0001.png", "target": 0.5} +{"file_name": "0002.png", "target": 0.7} +{"file_name": "0003.png", "target": 0.3} +``` + +Please note that metadata.jsonl should contain the `file_name` and the `target` value for each image. + +You can also use a dataset from the Hugging Face Hub. Example dataset from Hugging Face Hub: [abhishek/img-quality-full](https://huggingface.co/datasets/abhishek/img-quality-full). + +### Image Requirements + +- Format: Ensure all images are in JPEG, JPG, or PNG format. + +- Quantity: Include at least 5 images per class to provide the model with sufficient examples for learning. + +- Exclusivity: The zip file should exclusively contain folders named after the classes, +and these folders should only contain relevant images. No additional files or nested +folders should be included. + + +** Additional Tips** + +- Uniformity: While not required, having images of similar sizes and resolutions can help improve model performance. + +- Variability: Include a variety of images for each class to encompass the range of +appearances and contexts the model might encounter in real-world scenarios. + +Some points to keep in mind: + +- The zip file should contain multiple folders (the classes), each folder should contain images of a single class. +- The name of the folder should be the name of the class. +- The images must be jpeg, jpg or png. +- There should be at least 5 images per class. +- There must not be any other files in the zip file. +- There must not be any other folders inside the zip folder. + +When train.zip is decompressed, it creates two folders: cats and dogs. these are the two categories for classification. The images for both categories are in their respective folders. You can have as many categories as you want. + +## Column Mapping + +For image classification, if you are using a `zip` dataset format, the column mapping should be default and should not be changed. + +```yaml +data: + . + . + . + column_mapping: + image_column: image + target_column: label +``` + +For image regression, the column mapping must be as follows: + +```yaml +data: + . + . + . + column_mapping: + image_column: image + target_column: target +``` + +For image regression, `metadata.jsonl` should contain the `file_name` and the `target` value for each image. + +If you are using a dataset from the Hugging Face Hub, you should set appropriate column mappings based on the dataset. + + +## Training + +### Local Training + +To train the model locally, create a configuration file (config.yaml) with the following content: + +```yaml +task: image_classification +base_model: google/vit-base-patch16-224 +project_name: autotrain-cats-vs-dogs-finetuned +log: tensorboard +backend: local + +data: + path: cats_vs_dogs + train_split: train + valid_split: null + column_mapping: + image_column: image + target_column: label + +params: + epochs: 2 + batch_size: 4 + lr: 2e-5 + optimizer: adamw_torch + scheduler: linear + gradient_accumulation: 1 + mixed_precision: fp16 + +hub: + username: ${HF_USERNAME} + token: ${HF_TOKEN} + push_to_hub: true +``` + +Here, we are using `cats_and_dogs` dataset from Hugging Face Hub. The model is trained for 2 epochs with a batch size of 4 and a learning rate of `2e-5`. We are using the `adamw_torch` optimizer and the `linear` scheduler. We are also using mixed precision training with a gradient accumulation of 1. + +In order to use a local dataset, you can change the `data` section to: + +```yaml +data: + path: data/ + train_split: train # this folder inside data/ will be used for training, it contains the images in subfolders. + valid_split: valid # this folder inside data/ will be used for validation, it contains the images in subfolders. can also be null. + column_mapping: + image_column: image + target_column: label +``` + +Similarly, for image regression, you can use the following configuration file: + +```yaml +task: image_regression +base_model: microsoft/resnet-50 +project_name: autotrain-img-quality-resnet50 +log: tensorboard +backend: local + +data: + path: abhishek/img-quality-full + train_split: train + valid_split: null + column_mapping: + image_column: image + target_column: target + +params: + epochs: 10 + batch_size: 8 + lr: 2e-3 + optimizer: adamw_torch + scheduler: cosine + gradient_accumulation: 1 + mixed_precision: fp16 + +hub: + username: ${HF_USERNAME} + token: ${HF_TOKEN} + push_to_hub: true +``` + +To train the model, run the following command: + +```bash +$ autotrain --config config.yaml +``` + +This will start the training process and save the model to the Hugging Face Hub after training is complete. In case you dont want to save the model to the hub, you can set `push_to_hub` to `false` in the configuration file. + +### Training on Hugging Face Spaces + +To train the model on Hugging Face Spaces, create a training space as described in `Quickstart` section. + +An example UI for training an image scoring model on Hugging Face Spaces is shown below: + +![llm-finetuning](https://raw.githubusercontent.com/huggingface/autotrain-advanced/main/static/img_reg_ui.png) + +In this example, we are training an image scoring model using the `microsoft/resnet-50` model on the `abhishek/img-quality-full` dataset. +We are training the model for 3 epochs with a batch size of 8 and a learning rate of `5e-5`. +We are using the `adamw_torch` optimizer and the `linear` scheduler. +We are also using mixed precision training with a gradient accumulation of 1. + +Note how the column mapping has now been changed and `target` points to `quality_mos` column in the dataset. + +To train the model, click on the `Start Training` button. This will start the training process and save the model to the Hugging Face Hub after training is complete. + +## Parameters + +### Image Classification Parameters + +[[autodoc]] trainers.image_classification.params.ImageClassificationParams + +### Image Regression Parameters + +[[autodoc]] trainers.image_regression.params.ImageRegressionParams \ No newline at end of file diff --git a/docs/source/tasks/image_regression.mdx b/docs/source/tasks/image_regression.mdx deleted file mode 100644 index d6fb25fc38..0000000000 --- a/docs/source/tasks/image_regression.mdx +++ /dev/null @@ -1,58 +0,0 @@ -# Image Scoring/Regression - -Image scoring is a form of supervised learning where a model is trained to predict a -score or value for an image. AutoTrain simplifies the process, enabling you to train a -state-of-the-art image scoring model by simply uploading labeled example images. - - -## Preparing your data - -To ensure your image scoring model trains effectively, follow these guidelines for preparing your data: - - -### Organizing Images - - -Prepare a zip file containing your images and metadata.jsonl. - - -``` -Archive.zip -├── 0001.png -├── 0002.png -├── 0003.png -├── . -├── . -├── . -└── metadata.jsonl -``` - -Example for `metadata.jsonl`: - -``` -{"file_name": "0001.png", "target": 0.5} -{"file_name": "0002.png", "target": 0.7} -{"file_name": "0003.png", "target": 0.3} -``` - -Please note that metadata.jsonl should contain the `file_name` and the `target` value for each image. - - -### Image Requirements - -- Format: Ensure all images are in JPEG, JPG, or PNG format. - -- Quantity: Include at least 5 images to provide the model with sufficient examples for learning. - -- Exclusivity: The zip file should exclusively contain images and metadata.jsonl. -No additional files or nested folders should be included. - - -Some points to keep in mind: - -- The images must be jpeg, jpg or png. -- There should be at least 5 images per class. -- There must not be any other files in the zip file. -- There must not be any other folders inside the zip folder. - -When train.zip is decompressed, it creates no folders: only images and metadata.jsonl. \ No newline at end of file diff --git a/docs/source/tasks/object_detection.mdx b/docs/source/tasks/object_detection.mdx index a05d1bdc29..3d13309789 100644 --- a/docs/source/tasks/object_detection.mdx +++ b/docs/source/tasks/object_detection.mdx @@ -55,4 +55,8 @@ Some points to keep in mind: - There must not be any other files in the zip file. - There must not be any other folders inside the zip folder. -When train.zip is decompressed, it creates no folders: only images and metadata.jsonl. \ No newline at end of file +When train.zip is decompressed, it creates no folders: only images and metadata.jsonl. + +## Parameters + +[[autodoc]] trainers.object_detection.params.ObjectDetectionParams diff --git a/docs/source/tasks/seq2seq.mdx b/docs/source/tasks/seq2seq.mdx index e8505cdbcc..f798ea1606 100644 --- a/docs/source/tasks/seq2seq.mdx +++ b/docs/source/tasks/seq2seq.mdx @@ -30,3 +30,8 @@ Or as a JSONL file: ## Columns Your CSV/JSONL dataset must have two columns: `text` and `target`. + + +## Parameters + +[[autodoc]] trainers.seq2seq.params.Seq2SeqParams diff --git a/docs/source/tasks/tabular.mdx b/docs/source/tasks/tabular.mdx index 45374c9bf5..99bb980184 100644 --- a/docs/source/tasks/tabular.mdx +++ b/docs/source/tasks/tabular.mdx @@ -42,3 +42,8 @@ id,category1,category2,feature1,target ## Columns Your CSV dataset must have two columns: `id` and `target`. + + +## Parameters + +[[autodoc]] trainers.tabular.params.TabularParams diff --git a/docs/source/tasks/token_classification.mdx b/docs/source/tasks/token_classification.mdx index 704b6ec93f..d4a2b46db3 100644 --- a/docs/source/tasks/token_classification.mdx +++ b/docs/source/tasks/token_classification.mdx @@ -54,3 +54,8 @@ for chunk in pd.read_csv('example.csv', chunksize=chunk_size): ## Columns Your CSV/JSONL dataset must have two columns: `tokens` and `tags`. + + +## Parameters + +[[autodoc]] trainers.token_classification.params.TokenClassificationParams diff --git a/static/autotrain_space.png b/static/autotrain_space.png index 8cc8d1e56a..dec052a894 100644 Binary files a/static/autotrain_space.png and b/static/autotrain_space.png differ diff --git a/static/ext_qa.png b/static/ext_qa.png new file mode 100644 index 0000000000..215a5cbf6e Binary files /dev/null and b/static/ext_qa.png differ diff --git a/static/img_reg_ui.png b/static/img_reg_ui.png new file mode 100644 index 0000000000..99e6f198b8 Binary files /dev/null and b/static/img_reg_ui.png differ