FineTune_Mistral
A Python package for fine-tuning the Mistral model and generating responses based on provided questions. You can find instructions on how to prepare the training dataset from FragenAntwortLLMGPU or FragenAntwortLLMCPU.
Installation
pip uninstall FineTune_Mistral
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 (refer https://pytorch.org/get-started/locally/)
pip install FineTune_Mistral
Usage
# Usage example for FineTune_Mistral class
# In this library, the model used is mistralai/Mistral-7B-v0.1.
from FineTune_Mistral import FineTune_Mistral
# Define paths for dataset, cache, and output directory
dataset_path = 'path/to/your/dataset.jsonl'
cache_dir = 'path/to/cache'
output_dir = 'path/to/output'
base_model_path = 'path/to/base_model' # use the cache_dir
fine_tuned_model_path = output_dir # Assuming the fine-tuned model is saved in the output directory
merged_model_output_dir = 'path/to/merged_model_output'
# Obtain your Hugging Face API token (write permission)
hf_token = "your_huggingface_token_here"
# Instantiate the FineTune_Mistral class
fine_tuner = FineTune_Mistral(dataset_path, cache_dir, token=hf_token)
# Train the model
fine_tuner.train_model(output_dir=output_dir, num_train_epochs=3, per_device_train_batch_size=2, per_device_eval_batch_size=1)
# Parameters for response generation
max_new_tokens = 500
temperature = 0.1
question = "What is the capital of France?"
# Generate a response to the question
response = fine_tuner.generate_response(question, max_new_tokens=max_new_tokens, temperature=temperature)
print("Generated response:", response)
# Perform selective merge and save the merged model
merged_model = fine_tuner.selective_merge(
base_model_path=base_model_path,
fine_tuned_model_path=output_dir,
output_dir=merged_model_output_dir
)
print("Merged model saved to:", merged_model_output_dir)
Explanation of Parameters
dataset_path: Specifies the path to the dataset file in JSONL format. This dataset will be used for training the model.cache_dir: Directory for caching model files and other intermediate data. This helps in reusing downloaded files and speeding up the process. It is also used as the path to the base model in theselective_mergemethod.output_dir: Directory where the trained model, logs, and other outputs will be saved after training. It is also used as the path to the fine-tuned model in theselective_mergemethod.merged_model_output_dir: Directory where the merged model will be saved after using theselective_mergemethod.hf_token: Hugging Face API token for accessing gated repositories. Obtain it from Hugging Face Tokens.num_train_epochs: The number of epochs to train the model. An epoch is one complete pass through the training dataset. More epochs can lead to better model performance but also increase training time.per_device_train_batch_size: The batch size used during training for each device (e.g., GPU). A larger batch size can speed up training but requires more memory.per_device_eval_batch_size: The batch size used during evaluation for each device. Similar to training batch size but used during model evaluation.question: The input question for which the model should generate a response.max_new_tokens: The maximum number of new tokens (words or pieces of words) the model should generate in response to the input question.temperature: The temperature rate for generating responses. Lower values make the output more deterministic and higher values make it more random.
FineTune_Mistral
A Python package for fine-tuning the Mistral model and generating responses based on provided questions.
Features
This package provides functionalities to fine-tune the Mistral model, a causal language model designed for generating coherent and contextually relevant text. The key features include:
- Model Fine-Tuning: Fine-tune the Mistral model on a custom dataset to adapt it to specific tasks or domains.
- Response Generation: Generate contextually relevant responses based on provided questions.
- Easy Integration: Simple and easy-to-use interface for integrating model fine-tuning and response generation into your applications.
- Resource Management: Efficiently manage computational resources with built-in cleanup functions.
The package specifically fine-tunes the "mistralai/Mistral-7B-v0.1" model, adapting it to the custom dataset provided by the user.
Contributing
Contributions are welcome! Please fork this repository and submit pull requests.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Authors
- Mehrdad Almasi, Demival VASQUES FILHO, and Lars Wieneke
Contact
For questions or feedback, please contact Mehrdad.al.2023@gmail.com, demival.vasques@uni.lu, lars.wieneke@gmail.com.
Metadata
Release files for FineTune-Mistral 0.1.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| FineTune_Mistral-0.1.14.tar.gz | 6.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| FineTune_Mistral-0.1.14-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.1 kB
Release files / FineTune_Mistral-0.1.14.tar.gz
| Download URL | FineTune_Mistral-0.1.14.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c75cc84b000d3b1bb7e46ec3478ae58f7ef884f47dd8eecb6de2406ffe8aa1f
|
|
BLAKE2b-256 checksum How to use checksums |
63344fe4a035c5561151475ef882432266950489ea68a41a7b13a20efd99d452
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.13
|
Release files / FineTune_Mistral-0.1.14-py3-none-any.whl
| Download URL | FineTune_Mistral-0.1.14-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
96a891a57be2bdef1671d82c83a3722a7f9b393e3fc14b7896ee11a30c2fd85c
|
|
BLAKE2b-256 checksum How to use checksums |
a6819f19e9179ed21f0e958644c23433fc3ca7ec7212ac8837a589ce233b1960
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.13
|
Security for FineTune-Mistral 0.1.14
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.