Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into alekseymalakhov11-upd…
Browse files Browse the repository at this point in the history
…ate-ci-cd
  • Loading branch information
Малахов Алексей Павлович committed Aug 24, 2024
2 parents 57e42a7 + 1d999de commit 4d97861
Show file tree
Hide file tree
Showing 70 changed files with 774 additions and 4,723 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ ifneq ($(CODE),)
unify --in-place --recursive $(CODE) tutorials
endif

bash-dev:
docker run -v $(shell pwd):/app --rm -it ${DEV_IMAGE} bash

lock:
rm poetry.lock
poetry lock
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Turbo-Alignment supports a wide range of methods for model training and alignmen
- **📏** Length
- **🌀** Perplexity
- **🌟** METEOR
- **📐** RAGAS
- **🔍** Retrieval Utility

<a name="-how-to-use"></a>
Expand Down Expand Up @@ -86,7 +85,7 @@ Examples of datasets are available [here](docs/dataset_example.md).
- [RSO](#-RSO-sampling)
- [Common](#-common)
- [Preprocess](#-preprocess-common)
- [Convert to base](#-convert-to-base-common)
- [Merge adapters to base](#-merge-adapters-to-base-common)

<a name="-train"></a>
# Train
Expand Down Expand Up @@ -170,7 +169,9 @@ To launch RAG:
## 🚀 Installation

### 📦 Python Package
⌛️ in progress..
```bash
pip install turbo-alignment
```

### 🛠️ From Source
For the latest features before an official release:
Expand Down
40 changes: 38 additions & 2 deletions docs/dataset_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [Pair Preferences Dataset](#-pair-preferences-dataset)
- [KTO Dataset](#-kto-dataset)
- [Sampling Dataset](#-sampling-dataset)
- [Multimodal Dataset ](#-multimodal-dataset) (⌛️ Work in progress...)
- [Multimodal Dataset ](#-multimodal-dataset)
- [Classification Dataset](#-classification-dataset)
- [DPPO Dataset](#-ddpo-dataset) (⌛️ Work in progress...)

Expand Down Expand Up @@ -118,9 +118,45 @@ Example:

<a name="-multimodal-dataset"></a>
## Multimodal Dataset
⌛️ in progress..

- `messages`: `list[MultimodalChatMessage]` — This is a sequence of messages that make up the chat history. Each `ChatMessage` includes:
- `role` - The participant's role in the conversation (e.g., `user` or `bot`).
- `type` – The type of modality (e.g., `text` or `image`)
- `content` - If the `type` is `text`, it's the textual content of the message. If it's `image`, it's the file path.

Example:
```json
{
"id": "0",
"messages": [
{
"role": "system",
"type": "text",
"content": "You are a Multimodal AI assistant."
},
{
"role": "user",
"type": "image",
"content": "/path/to/cat.jpg"
},
{
"role": "user",
"type": "image",
"content": "/path/to/dog.jpg"
},
{
"role": "user",
"type": "text",
"content": "What's the difference between these two images?"
},
{
"role": "bot",
"type": "text",
"content": "The two images in question both feature animals, albeit of different species. The first image depicts a dog, which is generally perceived as an animal that elicits positive emotional responses. The second image features a cat, which is also regarded as an animal that evokes a positive emotional response."
}
]
}
```


<a name="-classification-dataset"></a>
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "turbo-alignment"
packages = [
{ include = "turbo_alignment" },
]
version = "0.1.0"
version = "0.0.2"
description = "turbo-alignment repository"
authors = ["T Mega Alignment Team <[email protected]>" ]

Expand Down Expand Up @@ -44,7 +44,6 @@ pydantic ="^2.7.0"
timm ="^0.9.7"
opencv-python = "^4.10.0.84"
langchain-huggingface = "^0.0.3"
ragas = "^0.1.10"

[tool.poetry.group.deepspeed.dependencies]
accelerate = "0.27"
Expand Down
5 changes: 4 additions & 1 deletion tests/cli/test_dpo_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

@pytest.mark.parametrize(
'config_path',
[FIXTURES_PATH / 'configs/train/dpo/base.json'],
[
FIXTURES_PATH / 'configs/train/dpo/base.json',
FIXTURES_PATH / 'configs/train/dpo/simpo.json',
],
)
def test_dpo_train(config_path: Path):
result = runner.invoke(
Expand Down
42 changes: 21 additions & 21 deletions tests/cli/test_multimodal_inference.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# from pathlib import Path
from pathlib import Path

# import pytest
# from typer.testing import CliRunner
import pytest
from typer.testing import CliRunner

# from tests.constants import FIXTURES_PATH
# from turbo_alignment.cli import app
# from turbo_alignment.settings.pipelines.inference.multimodal import (
# MultimodalInferenceExperimentSettings,
# )
from tests.constants import FIXTURES_PATH
from turbo_alignment.cli import app
from turbo_alignment.settings.pipelines.inference.multimodal import (
MultimodalInferenceExperimentSettings,
)

# runner = CliRunner()
runner = CliRunner()


# @pytest.mark.parametrize(
# 'config_path',
# [
# FIXTURES_PATH / 'configs/inference/multimodal/llama_llava_clip_pickle.json',
# ],
# )
# def test_multimodal_inference_mlp_with_preprocessing(config_path: Path):
# result = runner.invoke(
# app, ['inference_multimodal', '--inference_settings_path', str(config_path)], catch_exceptions=False
# )
# assert result.exit_code == 0
# assert MultimodalInferenceExperimentSettings.parse_file(config_path).save_path.is_dir()
@pytest.mark.parametrize(
'config_path',
[
FIXTURES_PATH / 'configs/inference/multimodal/llama_llava_clip_pickle.json',
],
)
def test_multimodal_inference_mlp_with_preprocessing(config_path: Path):
result = runner.invoke(
app, ['inference_multimodal', '--inference_settings_path', str(config_path)], catch_exceptions=False
)
assert result.exit_code == 0
assert MultimodalInferenceExperimentSettings.parse_file(config_path).save_path.is_dir()
16 changes: 1 addition & 15 deletions tests/cli/test_sft.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,10 @@
'config_path',
[
FIXTURES_PATH / 'configs/train/sft/base.json',
FIXTURES_PATH / 'configs/train/sft/sft_with_rm_metric.json',
],
)
def test_sft_train(config_path: Path):
result = runner.invoke(app, ['train_sft', '--experiment_settings_path', str(config_path)], catch_exceptions=False)
assert result.exit_code == 0
assert SftTrainExperimentSettings.parse_file(config_path).log_path.is_dir()


@pytest.mark.parametrize(
'config_path',
[
FIXTURES_PATH / 'configs/train/sft/resume_from_checkpoint.json',
],
)
def test_sft_from_checkpoint(config_path: Path):
result = runner.invoke(
app,
['train_sft', '--experiment_settings_path', str(config_path)],
)
assert result.exit_code == 0
assert SftTrainExperimentSettings.parse_file(config_path).log_path.is_dir()
2 changes: 1 addition & 1 deletion tests/fixtures/configs/inference/rag/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"num_beams": 1,
"max_new_tokens": 10,
"repetition_penalty": 1.2,
"stop_strings": "</RS>",
"do_sample": false
},
"custom_settings": {
"generation_eos_token": "</RS>",
"skip_special_tokens": false,
"remove_prompt": false
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/configs/train/dpo/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"generator_transformers_settings": {
"num_beams": 1,
"do_sample": false,
"stop_strings": "</RS>",
"max_new_tokens": 8
},
"custom_generation_settings": {
"generation_eos_token": "</RS>",
"skip_special_tokens": false
},
"dataset_settings": {
Expand Down
134 changes: 134 additions & 0 deletions tests/fixtures/configs/train/dpo/simpo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"train_dataset_settings": {
"sources": [
{
"name": "rm_preferences_test",
"records_path": "tests/fixtures/datasets/rm/train_preferences.jsonl",
"sample_rate": 1
}
],
"chat_settings":{
"prompt_template": {
"role_tag_mapping": {
"bot": "<bot>",
"user": "<user>",
"system": "<system>"
},
"prefix_template": "<RS>{role}",
"suffix_template": "</RS>"
},
"max_tokens_count": 120
},
"add_labels": true,
"dataset_type": "pair_preferences"
},
"val_dataset_settings": {
"sources": [
{
"name": "rm_preferences_test",
"records_path": "tests/fixtures/datasets/rm/val_preferences.jsonl",
"sample_rate": 1
}
],
"chat_settings":{
"prompt_template": {
"role_tag_mapping": {
"bot": "<bot>",
"user": "<user>",
"system": "<system>"
},
"prefix_template": "<RS>{role}",
"suffix_template": "</RS>"
},
"max_tokens_count": 120
},
"add_labels": true,
"dataset_type": "pair_preferences"
},
"model_settings": {
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "causal",
"transformers_settings": {},
"adapter_path": "tests/fixtures/models/llama2_tiny_fine_tuned_with_adapters/trainer",
"is_trainable": true
},
"cherry_pick_settings": {
"generator_transformers_settings": {
"num_beams": 1,
"do_sample": false,
"stop_strings": "</RS>",
"max_new_tokens": 8
},
"custom_generation_settings": {
"skip_special_tokens": false
},
"dataset_settings": {
"sources": [
{
"name": "chat_test",
"records_path": "tests/fixtures/datasets/chat/train_chat.jsonl",
"num_samples": 2
}
],
"prompt_template": {
"role_tag_mapping": {
"bot": "<bot>",
"user": "<user>",
"system": "<system>"
},
"prefix_template": "<RS>{role}",
"suffix_template": "</RS>"
},
"dataset_type": "chat",
"max_tokens_count": 150,
"only_answer_loss": true
},
"metric_settings": [
{
"type": "length",
"parameters": {"need_average": [true]}
},
{
"type": "kl",
"parameters": {
"need_average": [true],
"ref_logits_type": "sft"
}
}
]
},
"tokenizer_settings": {},
"trainer_settings": {
"evaluation_strategy": "steps",
"per_device_train_batch_size": 2,
"per_device_eval_batch_size": 2,
"gradient_accumulation_steps": 2,
"eval_steps": 4,
"save_steps": 4,
"logging_steps": 1,
"learning_rate": 0.0003,
"num_train_epochs": 2,
"lr_scheduler_type": "cosine",
"warmup_steps": 2,
"fp16": false,
"bf16": false,
"optim": "adamw_torch",
"save_total_limit": 1,
"average_log_prob": true,
"loss_settings": {
"loss_type": "simpo"
},
"sync_ref_settings": {
"sync_ref_model": false
},
"use_ref_model": false,
"use_sft_model": true,
"no_cuda": true
},
"wandb_settings": {
"project_name": "alignment",
"run_name": "dpo",
"entity": "turbo-alignment"
},
"log_path": "test_dpo_llama_train_output"
}
2 changes: 1 addition & 1 deletion tests/fixtures/configs/train/kto/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
"generator_transformers_settings": {
"num_beams": 1,
"do_sample": false,
"stop_strings": "</RS>",
"max_new_tokens": 8
},
"custom_generation_settings": {
"generation_eos_token": "</RS>",
"skip_special_tokens": false
},
"dataset_settings": {
Expand Down
Loading

0 comments on commit 4d97861

Please sign in to comment.