|
6 | 6 | "id": "gOpYt-Zgspvw" |
7 | 7 | }, |
8 | 8 | "source": [ |
9 | | - "To run this, press \"*Runtime*\" and press \"*Run all*\" on a **free** Tesla T4 Google Colab instance!\n", |
| 9 | + "To run this, press \"*Runtime*\" and press \"*Run all*\" on a Google Colab A100 instance!\n", |
10 | 10 | "<div class=\"align-center\">\n", |
11 | 11 | "<a href=\"https://unsloth.ai/\"><img src=\"https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png\" width=\"115\"></a>\n", |
12 | 12 | "<a href=\"https://discord.gg/unsloth\"><img src=\"https://github.com/unslothai/unsloth/raw/main/images/Discord button.png\" width=\"145\"></a>\n", |
|
75 | 75 | " xformers = 'xformers==' + {'2.10':'0.0.34','2.9':'0.0.33.post1','2.8':'0.0.32.post2'}.get(v, \"0.0.34\")\n", |
76 | 76 | " !pip install sentencepiece protobuf \"datasets==4.3.0\" \"huggingface_hub>=0.34.0\" hf_transfer\n", |
77 | 77 | " !pip install --no-deps unsloth_zoo bitsandbytes accelerate {xformers} peft trl triton unsloth\n", |
78 | | - "!pip install --no-deps git+https://github.com/huggingface/transformers.git\n", |
| 78 | + "!pip install --no-deps transformers==5.5.0\n", |
79 | 79 | "!pip install torchcodec\n", |
80 | 80 | "import torch; torch._dynamo.config.recompile_limit = 64;" |
81 | 81 | ] |
|
112 | 112 | "from unsloth import FastVisionModel # FastLanguageModel for LLMs\n", |
113 | 113 | "import torch\n", |
114 | 114 | "\n", |
115 | | - "# 4bit pre quantized models we support for 4x faster downloading + no OOMs.\n", |
116 | | - "fourbit_models = [\n", |
117 | | - " # Gemma 4 models\n", |
| 115 | + "gemma4_models = [\n", |
| 116 | + " # Gemma-4 instruct models:\n", |
118 | 117 | " \"unsloth/gemma-4-E2B-it\",\n", |
119 | | - " \"unsloth/gemma-4-E2B\",\n", |
| 118 | + " \"unsloth/gemma-4-E4B-it\",\n", |
| 119 | + " \"unsloth/gemma-4-31B-it\",\n", |
120 | 120 | " \"unsloth/gemma-4-26B-A4B-it\",\n", |
| 121 | + " # Gemma-4 base models:\n", |
| 122 | + " \"unsloth/gemma-4-E2B\",\n", |
121 | 123 | " \"unsloth/gemma-4-E4B\",\n", |
122 | | - " \"unsloth/gemma-4-31B-it\",\n", |
123 | 124 | " \"unsloth/gemma-4-31B\",\n", |
124 | | - " \"unsloth/gemma-4-26B-A4B-it\",\n", |
125 | 125 | " \"unsloth/gemma-4-26B-A4B\",\n", |
126 | 126 | "] # More models at https://huggingface.co/unsloth\n", |
127 | 127 | "\n", |
|
394 | 394 | }, |
395 | 395 | "outputs": [], |
396 | 396 | "source": [ |
397 | | - "FastVisionModel.for_inference(model) # Enable for inference!\n", |
398 | | - "\n", |
399 | 397 | "image = dataset[2][\"image\"]\n", |
400 | 398 | "instruction = \"Write the LaTeX representation for this image.\"\n", |
401 | 399 | "\n", |
|
453 | 451 | "from unsloth.trainer import UnslothVisionDataCollator\n", |
454 | 452 | "from trl import SFTTrainer, SFTConfig\n", |
455 | 453 | "\n", |
456 | | - "FastVisionModel.for_training(model) # Enable for training!\n", |
457 | | - "\n", |
458 | 454 | "trainer = SFTTrainer(\n", |
459 | 455 | " model = model,\n", |
460 | 456 | " train_dataset = converted_dataset,\n", |
|
463 | 459 | " args = SFTConfig(\n", |
464 | 460 | " per_device_train_batch_size = 1,\n", |
465 | 461 | " gradient_accumulation_steps = 4,\n", |
466 | | - " gradient_checkpointing = True,\n", |
467 | | - "\n", |
468 | | - " # use reentrant checkpointing\n", |
469 | | - " gradient_checkpointing_kwargs = {\"use_reentrant\": False},\n", |
470 | | - " max_grad_norm = 0.3, # max gradient norm based on QLoRA paper\n", |
| 462 | + " max_grad_norm = 0.3,\n", |
471 | 463 | " warmup_ratio = 0.03,\n", |
472 | 464 | " max_steps = 60,\n", |
473 | | - " #num_train_epochs = 2, # Set this instead of max_steps for full training runs\n", |
| 465 | + " # num_train_epochs = 2, # Set this instead of max_steps for full training runs\n", |
474 | 466 | " learning_rate = 2e-4,\n", |
475 | 467 | " logging_steps = 1,\n", |
476 | 468 | " save_strategy = \"steps\",\n", |
477 | | - " optim = \"adamw_torch_fused\",\n", |
| 469 | + " optim = \"adamw_8bit\",\n", |
478 | 470 | " weight_decay = 0.001,\n", |
479 | 471 | " lr_scheduler_type = \"cosine\",\n", |
480 | 472 | " seed = 3407,\n", |
481 | 473 | " output_dir = \"outputs\",\n", |
482 | | - " report_to = \"none\", # For Weights and Biases\n", |
| 474 | + " report_to = \"none\", # For Weights and Biases or others\n", |
483 | 475 | "\n", |
484 | 476 | " # You MUST put the below items for vision finetuning:\n", |
485 | 477 | " remove_unused_columns = False,\n", |
|
563 | 555 | }, |
564 | 556 | "outputs": [], |
565 | 557 | "source": [ |
566 | | - "FastVisionModel.for_inference(model) # Enable for inference!\n", |
567 | | - "\n", |
568 | 558 | "image = dataset[10][\"image\"]\n", |
569 | 559 | "instruction = \"Write the LaTeX representation for this image.\"\n", |
570 | 560 | "\n", |
|
642 | 632 | " model_name = \"gemma_4_lora\", # YOUR MODEL YOU USED FOR TRAINING\n", |
643 | 633 | " load_in_4bit = True, # Set to False for 16bit LoRA\n", |
644 | 634 | " )\n", |
645 | | - " FastVisionModel.for_inference(model) # Enable for inference!\n", |
646 | | - "\n", |
647 | | - "FastVisionModel.for_inference(model) # Enable for inference!\n", |
648 | 635 | "\n", |
649 | 636 | "sample = dataset[1]\n", |
650 | 637 | "image = sample[\"image\"].convert(\"RGB\")\n", |
|
0 commit comments