diff --git a/.gitignore b/.gitignore index 9bf1836..6b80573 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ **.egg-info/ +**/_unsloth_temporary_saved_buffers/ .env __pycache__/ collect.txt diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 10df645..ad3a4da 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -12,10 +12,10 @@ export MSYS_NO_PATHCONV=1 # Pod configuration GPU_TYPE=${GPU_TYPE:-"NVIDIA RTX 6000 Ada Generation"} GPU_COUNT=${GPU_COUNT:-1} -CONTAINER_DISK_SIZE=${CONTAINER_DISK_SIZE:-100} # GB +CONTAINER_DISK_SIZE=${CONTAINER_DISK_SIZE:-200} # GB CPU_COUNT=${CPU_COUNT:-1} # vCPUs POD_NAME=${POD_NAME:-"sia-agent"} -VOLUME_SIZE=${VOLUME_SIZE:-200} # GB +VOLUME_SIZE=${VOLUME_SIZE:-50} # GB VOLUME_PATH=${VOLUME_PATH:-"/root/data"} # Mount path within container # Docker configuration diff --git a/tools/train/train/qwq.ipynb b/tools/train/train/qwq.ipynb index 4404e33..f7fa300 100644 --- a/tools/train/train/qwq.ipynb +++ b/tools/train/train/qwq.ipynb @@ -2,40 +2,9 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/root/venvs/train/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "🦥 Unsloth Zoo will now patch everything to make training faster!\n", - "INFO 03-28 15:57:36 [__init__.py:239] Automatically detected platform cuda.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2025-03-28 15:57:36,647\tINFO util.py:154 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n" - ] - } - ], + "outputs": [], "source": [ "# Unsloth should be imported before transformers to ensure all optimizations are applied.\n", "from unsloth import FastLanguageModel, is_bfloat16_supported" @@ -43,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -58,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -67,7 +36,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -76,38 +45,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Validating 20 XML files...\n", - "file: /root/sia/training/clean_start/iteration_20250116_134549_655.xml\n", - "file: /root/sia/training/clean_start/iteration_20250116_134555_680.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141241_092.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141252_317.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141302_940.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141329_886.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141343_416.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141357_412.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141410_965.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141428_204.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141441_443.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141447_231.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141454_509.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141458_495.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141503_889.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141516_718.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141533_231.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141603_549.xml\n", - "file: /root/sia/training/delete_indicated_entries/iteration_20250116_141633_083.xml\n", - "file: /root/sia/training/list_entries_to_delete/iteration_20250116_141227_271.xml\n", - "Validation complete. Found 20 valid files.\n" - ] - } - ], + "outputs": [], "source": [ "dataset = qwq.Dataset(args.config_path)\n", "dataset.validate()" @@ -115,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -125,106 +65,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "==((====))== Unsloth 2025.3.19: Fast Qwen2 patching. Transformers: 4.50.2. vLLM: 0.8.2.\n", - " \\\\ /| NVIDIA RTX 6000 Ada Generation. Num GPUs = 1. Max memory: 47.5 GB. Platform: Linux.\n", - "O^O/ \\_/ \\ Torch: 2.6.0+cu124. CUDA: 8.9. CUDA Toolkit: 12.4. Triton: 3.2.0\n", - "\\ / Bfloat16 = TRUE. FA [Xformers = 0.0.29.post2. FA2 = False]\n", - " \"-____-\" Free license: http://github.com/unslothai/unsloth\n", - "Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!\n", - "Unsloth: vLLM loading unsloth/qwq-32b-unsloth-bnb-4bit with actual GPU utilization = 84.18%\n", - "Unsloth: Your GPU has CUDA compute capability 8.9 with VRAM = 47.5 GB.\n", - "Unsloth: Using conservativeness = 1.0. Chunked prefill tokens = 2048. Num Sequences = 288.\n", - "Unsloth: vLLM's KV Cache can use up to 17.92 GB. Also swap space = 6 GB.\n", - "INFO 03-28 15:59:12 [config.py:585] This model supports multiple tasks: {'score', 'classify', 'embed', 'reward', 'generate'}. Defaulting to 'generate'.\n", - "WARNING 03-28 15:59:12 [arg_utils.py:1854] --quantization bitsandbytes is not supported by the V1 Engine. Falling back to V0. \n", - "Unsloth: vLLM Bitsandbytes config using kwargs = {'load_in_8bit': False, 'load_in_4bit': True, 'bnb_4bit_compute_dtype': 'bfloat16', 'bnb_4bit_quant_storage': 'uint8', 'bnb_4bit_quant_type': 'nf4', 'bnb_4bit_use_double_quant': True, 'llm_int8_enable_fp32_cpu_offload': False, 'llm_int8_has_fp16_weight': False, 'llm_int8_skip_modules': ['lm_head', 'multi_modal_projector', 'merger', 'modality_projection', 'model.layers.4.mlp', 'model.layers.0.mlp', 'model.layers.60.mlp', 'model.layers.62.mlp', 'model.layers.5.mlp', 'model.layers.43.self_attn'], 'llm_int8_threshold': 6.0}\n", - "INFO 03-28 15:59:12 [llm_engine.py:241] Initializing a V0 LLM engine (v0.8.2) with config: model='unsloth/qwq-32b-unsloth-bnb-4bit', speculative_config=None, tokenizer='unsloth/qwq-32b-unsloth-bnb-4bit', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, override_neuron_config=None, tokenizer_revision=None, trust_remote_code=False, dtype=torch.bfloat16, max_seq_len=2048, download_dir=None, load_format=bitsandbytes, tensor_parallel_size=1, pipeline_parallel_size=1, disable_custom_all_reduce=False, quantization=bitsandbytes, enforce_eager=False, kv_cache_dtype=auto, device_config=cuda:0, decoding_config=DecodingConfig(guided_decoding_backend='xgrammar', reasoning_backend=None), observability_config=ObservabilityConfig(show_hidden_metrics=False, otlp_traces_endpoint=None, collect_model_forward_time=False, collect_model_execute_time=False), seed=0, served_model_name=unsloth/qwq-32b-unsloth-bnb-4bit, num_scheduler_steps=1, multi_step_stream_outputs=True, enable_prefix_caching=True, chunked_prefill_enabled=False, use_async_output_proc=True, disable_mm_preprocessor_cache=False, mm_processor_kwargs=None, pooler_config=None, compilation_config={\"level\":0,\"splitting_ops\":[],\"compile_sizes\":[],\"cudagraph_capture_sizes\":[288,280,272,264,256,248,240,232,224,216,208,200,192,184,176,168,160,152,144,136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,4,2,1],\"max_capture_size\":288}, use_cached_outputs=False, \n", - "INFO 03-28 15:59:13 [cuda.py:291] Using Flash Attention backend.\n", - "INFO 03-28 15:59:13 [parallel_state.py:954] rank 0 in world size 1 is assigned as DP rank 0, PP rank 0, TP rank 0\n", - "INFO 03-28 15:59:13 [model_runner.py:1110] Starting to load model unsloth/qwq-32b-unsloth-bnb-4bit...\n", - "INFO 03-28 15:59:14 [loader.py:1155] Loading weights with BitsAndBytes quantization. May take a while ...\n", - "INFO 03-28 15:59:14 [weight_utils.py:265] Using model weights format ['*.safetensors']\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Loading safetensors checkpoint shards: 0% Completed | 0/5 [00:00\\n\\n\\n\\n \\n \\n \\n \\n \\n \\n\\n \\n \\n \\n \\n\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n\\n \\n \\n \\n \\n \\n \\n \\n \\n\\n \\n \\n \\n \\n\\n \\n \\n \\n \\n \\n \\n \\n \\n\\n'},\n", - " {'role': 'user',\n", - " 'content': '\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\nAt node \"evaluate_test_results\". Entry 45f3d2 shows failed test: \"Error: Connection timeout\". \\nWill need to check system logs soon (noted in /tasks/reminders.txt, check at 14:00).\\nFirst focusing on this error.\\n\\n```\\n\\n## Reasons to Switch Procedures\\n\\nCommon triggers:\\n - Data available on stdin\\n - Time matching scheduled task\\n - Error conditions in script output\\n - Resource constraints detected\\n - User input needed]]>\\n \\n \\n \\n \\n \\n \\n Also load the last 10 messages from /user/conversation_history/ ]\\n PrepareForDraft{Have everything needed for drafting a message?}\\n DraftMessage[Draft message in reasoning entry]\\n ReadInput[Read input from standard input]\\n ReasonCleanContext[List id\\'s of entries that are no longer needed
Explain for each entry why it is no longer needed]\\n DeleteEntries[Remove the entries that are no longer needed
End by deleting the ReasonCleanContext entry]\\n AddHistoryUser[Add the message to the /user/conversation_history/ directory
The filename is the id of the stdin entry with .user extension]\\n LoadTask[Look for the task in the /tasks directory and load relevant files]\\n LoadUserDetails[Look in the /user directory for relevant files]\\n EstimateScript[Draft the script in a reasoning block and estimate its runtime and output length]\\n ScriptAcceptable{Does the draft script make sense and are the estimations short enough to not hinder the conversation?}\\n RunScript[Run the script, make sure to set appropriate timeout and output limits]\\n ReviewDraft{Is the message well structured and free of logical errors?}\\n SendMessage[Send the message using standard output]\\n AddHistoryAgent[Add the message to the /user/conversation_history/ directory
The filename is the id of the stdout entry with .agent extension]\\n ReasonResponse[Is the conversation ongoing?
How long is the user expected to take to respond?]\\n NeedAwaitResponse{Is it likely to get a response within a minute?}\\n BusyWait[Wait 1 second for the first busy wait, double the time each iteration until a response is received
Make sure to set the timout]\\n\\n End([Clean the context])\\n\\n Start --> LoadUserBasic\\n LoadUserBasic --> PrepareForDraft\\n\\n PrepareForDraft -->|Got all needed info| DraftMessage\\n PrepareForDraft -->|Getting the required info would slow the conversation| DraftMessage\\n PrepareForDraft -->|Input available on stdin| ReadInput\\n PrepareForDraft -->|Context usage more than 50%| ReasonCleanContext\\n PrepareForDraft -->|Task mentioned but not loaded| LoadTask\\n PrepareForDraft -->|Personal or social info mentioned but not loaded| LoadUserDetails\\n PrepareForDraft -->|Calculations, system info or other numerical values that can be scripted are mentioned| EstimateScript\\n\\n ReasonCleanContext --> DeleteEntries\\n DeleteEntries --> PrepareForDraft\\n\\n ReadInput --> AddHistoryUser\\n AddHistoryUser --> PrepareForDraft\\n\\n LoadTask --> PrepareForDraft\\n LoadUserDetails --> PrepareForDraft\\n\\n EstimateScript --> ScriptAcceptable\\n ScriptAcceptable -->|Acceptable| RunScript\\n ScriptAcceptable -->|Not acceptable| PrepareForDraft\\n RunScript --> PrepareForDraft\\n \\n DraftMessage --> ReviewDraft{Is this really what I want to say?}\\n ReviewDraft -->|Rewrite better| DraftMessage\\n ReviewDraft -->|Good message| SendMessage\\n \\n SendMessage --> AddHistoryAgent\\n AddHistoryAgent --> ReasonResponse\\n ReasonResponse --> NeedAwaitResponse\\n \\n NeedAwaitResponse -->|Quick response is unlikely| End\\n NeedAwaitResponse -->|Input available on stdin| PrepareForDraft\\n NeedAwaitResponse -->|Quick response is likely| BusyWait\\n BusyWait --> NeedAwaitResponse\\n```]]>\\n
\\n \\n
\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n'},\n", - " {'role': 'assistant', 'content': ''}]}" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "dataset[5]" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "training_args = TrainingArguments(\n", + " output_dir=str(args.output_dir),\n", + " num_train_epochs=3,\n", + " per_device_train_batch_size=1,\n", + " gradient_accumulation_steps=16,\n", + " gradient_checkpointing=True,\n", + " learning_rate=2e-5,\n", + " lr_scheduler_type=\"cosine\",\n", + " warmup_ratio=0.05,\n", + " weight_decay=0.01,\n", + " fp16=not is_bfloat16_supported(),\n", + " bf16=is_bfloat16_supported(),\n", + " logging_steps=10,\n", + " save_steps=200,\n", + " save_total_limit=3,\n", + " report_to=\"none\",\n", + " optim=\"adamw_8bit\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "trainer = SFTTrainer(\n", + " model=model,\n", + " tokenizer=tokenizer,\n", + " args=training_args,\n", + " train_dataset=dataset.to_transformers_dataset(tokenizer),\n", + " dataset_text_field=\"messages\",\n", + " max_seq_length=max_seq_length,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "trainer.train()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "model.save_pretrained_merged(\n", + " str(args.output_dir), \n", + " tokenizer=tokenizer,\n", + " save_method=\"merged_16bit\"\n", + ")" + ] } ], "metadata": { "kernelspec": { "display_name": "train", "language": "python", - "name": "train" + "name": "python3" }, "language_info": { "codemirror_mode": {