Skip to content

Commit

Permalink
use none string not null
Browse files Browse the repository at this point in the history
  • Loading branch information
burtenshaw committed Jan 8, 2025
1 parent c45c240 commit 1082595
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 57 deletions.
18 changes: 8 additions & 10 deletions 2_preference_alignment/notebooks/dpo_finetuning_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"import os\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
"from datasets import load_dataset\n",
"from trl import DPOTrainer, DPOConfig\n"
"from trl import DPOTrainer, DPOConfig"
]
},
{
Expand Down Expand Up @@ -122,9 +122,7 @@
"device = (\n",
" \"cuda\"\n",
" if torch.cuda.is_available()\n",
" else \"mps\"\n",
" if torch.backends.mps.is_available()\n",
" else \"cpu\"\n",
" else \"mps\" if torch.backends.mps.is_available() else \"cpu\"\n",
")\n",
"\n",
"# Model to fine-tune\n",
Expand Down Expand Up @@ -269,7 +267,7 @@
" # Use bfloat16 precision for faster training\n",
" bf16=True,\n",
" # Disable wandb/tensorboard logging\n",
" report_to=None,\n",
" report_to=\"none\",\n",
" # Keep all columns in dataset even if not used\n",
" remove_unused_columns=False,\n",
" # Enable MPS (Metal Performance Shaders) for Mac devices\n",
Expand All @@ -282,7 +280,7 @@
" # Maximum length of the input prompt in tokens\n",
" max_prompt_length=1024,\n",
" # Maximum combined length of prompt + response in tokens\n",
" max_length=1536\n",
" max_length=1536,\n",
")"
]
},
Expand All @@ -303,11 +301,11 @@
" processing_class=tokenizer,\n",
" # DPO-specific temperature parameter that controls the strength of the preference model\n",
" # Lower values (like 0.1) make the model more conservative in following preferences\n",
" #beta=0.1,\n",
" # beta=0.1,\n",
" # Maximum length of the input prompt in tokens\n",
" #max_prompt_length=1024,\n",
" # max_prompt_length=1024,\n",
" # Maximum combined length of prompt + response in tokens\n",
" #max_length=1536,\n",
" # max_length=1536,\n",
")"
]
},
Expand Down Expand Up @@ -364,7 +362,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
"version": "3.11.10"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
" # Gradual learning rate warmup\n",
" warmup_steps=10,\n",
" # Disable external logging\n",
" report_to=None,\n",
" report_to=\"none\",\n",
" # Where to save model/checkpoints\n",
" output_dir=\"./results/\",\n",
" # Enable MPS (Metal Performance Shaders) if available\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
" bf16=True, # Use bfloat16 precision\n",
" # Integration settings\n",
" push_to_hub=False, # Don't push to HuggingFace Hub\n",
" report_to=None, # Disable external logging\n",
" report_to=\"none\", # Disable external logging\n",
")"
]
},
Expand Down
18 changes: 8 additions & 10 deletions es/2_preference_alignment/notebooks/dpo_finetuning_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"\n",
"login()\n",
"\n",
"# Para conveniencia, puedes crear una variable de entorno que contenga tu token de Hugging Face como HF_TOKEN\n"
"# Para conveniencia, puedes crear una variable de entorno que contenga tu token de Hugging Face como HF_TOKEN"
]
},
{
Expand All @@ -60,7 +60,7 @@
"import os\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
"from datasets import load_dataset\n",
"from trl import DPOTrainer, DPOConfig\n"
"from trl import DPOTrainer, DPOConfig"
]
},
{
Expand Down Expand Up @@ -121,9 +121,7 @@
"device = (\n",
" \"cuda\"\n",
" if torch.cuda.is_available()\n",
" else \"mps\"\n",
" if torch.backends.mps.is_available()\n",
" else \"cpu\"\n",
" else \"mps\" if torch.backends.mps.is_available() else \"cpu\"\n",
")\n",
"\n",
"# Modelo para afinar\n",
Expand All @@ -137,7 +135,7 @@
"\n",
"# Establece el nombre para el modelo afinado que se guardará y/o subirá\n",
"finetune_name = \"SmolLM2-FT-DPO\"\n",
"finetune_tags = [\"smol-course\", \"module_2\"]\n"
"finetune_tags = [\"smol-course\", \"module_2\"]"
]
},
{
Expand Down Expand Up @@ -268,14 +266,14 @@
" # Usar precisión bfloat16 para un entrenamiento más rápido\n",
" bf16=True,\n",
" # Desactivar los registros de wandb/tensorboard\n",
" report_to=None,\n",
" report_to=\"none\",\n",
" # Mantener todas las columnas en el dataset incluso si no se utilizan\n",
" remove_unused_columns=False,\n",
" # Habilitar MPS (Metal Performance Shaders) para dispositivos Mac\n",
" use_mps_device=device == \"mps\",\n",
" # ID del modelo para cargas al HuggingFace Hub\n",
" hub_model_id=finetune_name,\n",
")\n"
")"
]
},
{
Expand All @@ -300,7 +298,7 @@
" max_prompt_length=1024,\n",
" # Longitud máxima combinada de prompt + respuesta en tokens\n",
" max_length=1536,\n",
")\n"
")"
]
},
{
Expand All @@ -317,7 +315,7 @@
"\n",
"# Sube el modelo a Hugging Face si el inicio de sesión o HF_TOKEN está configurado\n",
"if os.getenv(\"HF_TOKEN\"):\n",
" trainer.push_to_hub(tags=finetune_tags)\n"
" trainer.push_to_hub(tags=finetune_tags)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"\n",
"# Autenticación en Hugging Face\n",
"from huggingface_hub import login\n",
"\n",
"login()"
]
},
Expand Down Expand Up @@ -258,9 +259,7 @@
"device = (\n",
" \"cuda\"\n",
" if torch.cuda.is_available()\n",
" else \"mps\"\n",
" if torch.backends.mps.is_available()\n",
" else \"cpu\"\n",
" else \"mps\" if torch.backends.mps.is_available() else \"cpu\"\n",
")\n",
"\n",
"# Modelo para afinar\n",
Expand All @@ -274,7 +273,7 @@
"\n",
"# Establece el nombre para guardar o subir el modelo afinado\n",
"finetune_name = \"SmolLM2-FT-DPO\"\n",
"finetune_tags = [\"smol-course\", \"module_2\"]\n"
"finetune_tags = [\"smol-course\", \"module_2\"]"
]
},
{
Expand Down Expand Up @@ -350,13 +349,13 @@
" # Calentamiento gradual de la tasa de aprendizaje\n",
" warmup_steps=10,\n",
" # Desactivar registro externo\n",
" report_to=None,\n",
" report_to=\"none\",\n",
" # Dónde guardar el modelo/puntos de control\n",
" output_dir=\"./results/\",\n",
" # Habilitar MPS (Metal Performance Shaders) si está disponible\n",
" use_mps_device=device == \"mps\",\n",
" hub_model_id=finetune_name,\n",
")\n"
")"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"\n",
"login()\n",
"\n",
"# Por comodidad, puedes crear una variable de entorno que contenga tu token de Hugging Face como HF_TOKEN\n"
"# Por comodidad, puedes crear una variable de entorno que contenga tu token de Hugging Face como HF_TOKEN"
]
},
{
Expand Down Expand Up @@ -249,7 +249,7 @@
" bf16=True, # Usar precisión bfloat16\n",
" # Configuración de integración\n",
" push_to_hub=False, # No subir a HuggingFace\n",
" report_to=None, # Desactivar registro externo\n",
" report_to=\"none\", # Desactivar registro externo\n",
")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
" bf16=True, # bfloat16 정밀도 사용\n",
" # 통합 설정\n",
" push_to_hub=False, # Hugging Face 허브로 내보내지 않음\n",
" report_to=None, # 외부 로깅 비활성화\n",
" report_to=\"none\", # 외부 로깅 비활성화\n",
")"
]
},
Expand Down Expand Up @@ -284,7 +284,7 @@
" packing=True, # 효율성을 위해 입력 패킹 활성화\n",
" dataset_kwargs={\n",
" \"add_special_tokens\": False, # 템플릿에서 추가 토큰 처리\n",
" \"append_concat_token\": False, # 추가 구분자 없음 \n",
" \"append_concat_token\": False, # 추가 구분자 없음\n",
" },\n",
")"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"import os\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
"from datasets import load_dataset\n",
"from trl import DPOTrainer, DPOConfig\n"
"from trl import DPOTrainer, DPOConfig"
]
},
{
Expand Down Expand Up @@ -122,9 +122,7 @@
"device = (\n",
" \"cuda\"\n",
" if torch.cuda.is_available()\n",
" else \"mps\"\n",
" if torch.backends.mps.is_available()\n",
" else \"cpu\"\n",
" else \"mps\" if torch.backends.mps.is_available() else \"cpu\"\n",
")\n",
"\n",
"# Model to fine-tune\n",
Expand Down Expand Up @@ -269,7 +267,7 @@
" # Use bfloat16 precision for faster training\n",
" bf16=True,\n",
" # Disable wandb/tensorboard logging\n",
" report_to=None,\n",
" report_to=\"none\",\n",
" # Keep all columns in dataset even if not used\n",
" remove_unused_columns=False,\n",
" # Enable MPS (Metal Performance Shaders) for Mac devices\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"\n",
"# Authenticate to Hugging Face\n",
"from huggingface_hub import login\n",
"\n",
"login()"
]
},
Expand Down Expand Up @@ -257,9 +258,7 @@
"device = (\n",
" \"cuda\"\n",
" if torch.cuda.is_available()\n",
" else \"mps\"\n",
" if torch.backends.mps.is_available()\n",
" else \"cpu\"\n",
" else \"mps\" if torch.backends.mps.is_available() else \"cpu\"\n",
")\n",
"\n",
"# Model to fine-tune\n",
Expand Down Expand Up @@ -349,7 +348,7 @@
" # Gradual learning rate warmup\n",
" warmup_steps=10,\n",
" # Disable external logging\n",
" report_to=None,\n",
" report_to=\"none\",\n",
" # Where to save model/checkpoints\n",
" output_dir=\"./results/\",\n",
" # Enable MPS (Metal Performance Shaders) if available\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@
"device = (\n",
" \"cuda\"\n",
" if torch.cuda.is_available()\n",
" else \"mps\"\n",
" if torch.backends.mps.is_available()\n",
" else \"cpu\"\n",
" else \"mps\" if torch.backends.mps.is_available() else \"cpu\"\n",
")\n",
"\n",
"# Mô hình để tinh chỉnh\n",
Expand Down Expand Up @@ -264,7 +262,7 @@
" # Sử dụng bfloat16 để tăng tốc huấn luyện\n",
" bf16=True,\n",
" # Tắt logging wandb/tensorboard\n",
" report_to=None,\n",
" report_to=\"none\",\n",
" # Giữ lại tất cả các cột trong dataset kể cả không sử dụng\n",
" remove_unused_columns=False,\n",
" # Bật MPS cho thiết bị Mac\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"\n",
"# Authenticate to Hugging Face\n",
"from huggingface_hub import login\n",
"\n",
"login()"
]
},
Expand Down Expand Up @@ -90,7 +91,7 @@
"metadata": {},
"outputs": [],
"source": [
"# TODO: 🐕 Nếu bộ dữ liệu của bạn không được biểu diễn dưới dạng danh sách hội thoại, \n",
"# TODO: 🐕 Nếu bộ dữ liệu của bạn không được biểu diễn dưới dạng danh sách hội thoại,\n",
"# bạn có thể sử dụng hàm `process_dataset` để chuyển đổi nó."
]
},
Expand Down Expand Up @@ -248,9 +249,7 @@
"device = (\n",
" \"cuda\"\n",
" if torch.cuda.is_available()\n",
" else \"mps\"\n",
" if torch.backends.mps.is_available()\n",
" else \"cpu\"\n",
" else \"mps\" if torch.backends.mps.is_available() else \"cpu\"\n",
")\n",
"\n",
"# Mô hình để tinh chỉnh\n",
Expand Down Expand Up @@ -315,7 +314,7 @@
" # Learning rate nhỏ để tránh catastrophic forgetting\n",
" # Đọc thêm về catastrophic forgetting: https://blog.vinbigdata.org/robot-co-the-hoc-suot-doi-khong/\n",
" learning_rate=8e-6,\n",
" # Giảm learning rate tuyến tính trong quá trình huấn luyện \n",
" # Giảm learning rate tuyến tính trong quá trình huấn luyện\n",
" lr_scheduler_type=\"linear\",\n",
" # Độ dài tối đa kết hợp của chỉ thị + câu trả lời\n",
" max_length=1024,\n",
Expand All @@ -333,15 +332,15 @@
" # Số epoch huấn luyện\n",
" num_train_epochs=1,\n",
" # Khi nào chạy đánh giá\n",
" evaluation_strategy=\"steps\", \n",
" evaluation_strategy=\"steps\",\n",
" # Đánh giá sau mỗi 20% huấn luyện\n",
" eval_steps=0.2,\n",
" # Ghi log metrics mỗi step\n",
" logging_steps=1,\n",
" # Tăng learning rate dần dần\n",
" warmup_steps=10,\n",
" # Tắt logging bên ngoài\n",
" report_to=None,\n",
" report_to=\"none\",\n",
" # Nơi lưu model/checkpoints\n",
" output_dir=\"./results/\",\n",
" # Bật MPS (Metal Performance Shaders) nếu có\n",
Expand Down
Loading

0 comments on commit 1082595

Please sign in to comment.