{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "X3HSf7KnG48q" }, "source": [ "## PaliGemma π€ Direct Preference Optimization" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "emG7uw6IdhFs", "outputId": "07ce2f98-6c3d-47b5-eca5-2d58271dce9e" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for transformers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n" ] } ], "source": [ "!pip install -q git+https://github.com/huggingface/transformers.git" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "XhqsZVjzDmt4", "outputId": "5fbc28d8-76aa-4f12-a97f-b00db5ff0e6d" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m314.1/314.1 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m547.8/547.8 kB\u001b[0m \u001b[31m10.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m103.4/103.4 kB\u001b[0m \u001b[31m14.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m21.3/21.3 MB\u001b[0m \u001b[31m51.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m40.8/40.8 MB\u001b[0m \u001b[31m28.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m116.3/116.3 kB\u001b[0m \u001b[31m15.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m64.9/64.9 kB\u001b[0m \u001b[31m8.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m194.1/194.1 kB\u001b[0m \u001b[31m24.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m134.8/134.8 kB\u001b[0m \u001b[31m18.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Building wheel for trl (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", "cudf-cu12 24.4.1 requires pyarrow<15.0.0a0,>=14.0.1, but you have pyarrow 16.1.0 which is incompatible.\n", "google-colab 1.0.0 requires requests==2.31.0, but you have requests 2.32.3 which is incompatible.\n", "ibis-framework 8.0.0 requires pyarrow<16,>=2, but you have pyarrow 16.1.0 which is incompatible.\u001b[0m\u001b[31m\n", "\u001b[0m" ] } ], "source": [ "!pip install -q git+https://github.com/qgallouedec/trl.git@main" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "nDXtvLWPTrbv", "outputId": "6b9a509a-4c0c-4928-ce59-1b697c32dfce" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m251.6/251.6 kB\u001b[0m \u001b[31m1.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m119.8/119.8 MB\u001b[0m \u001b[31m13.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h" ] } ], "source": [ "!pip install -q -U peft accelerate bitsandbytes" ] }, { "cell_type": "markdown", "metadata": { "id": "VibvptIEHkuY" }, "source": [ "Let's load the model and the processor. First we need to login using `notebook_login`Β since PaliGemma is a gated model. For utmost security, you can create a fine-grained token with access to PaliGemma and pass that." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 145, "referenced_widgets": [ "620ee05c533b465ab239668de96407a8", "19e2e45b6f25486f9ddfe1d44ed2dcd3", "1511916ac88946829246c12e1a840066", "1b2c9d4192e2400ea3cfbdfcf7efd3fd", "b5ee5a28ee8c46108e4153b19ac30ff5", "b6a4dc9f81fa45f79977c5ccdf7d76c6", "03c58dde001c4707b0ef430054092fb9", "bd7d3079fa0c4f94a1ec7bb153db6e75", "35bf9478026245339a743faa43cbe802", "0e6b906c77b4457cadc73f6f32d85f53", "432d4a63b1d44eb5968b22f5ed19bb91", "d859633d77ec4a758dfe3597ad1ebde6", "a39fad21b71f4e5789d5561e25d5b61e", "f746020cd83f487c9d418ef29f50e060", "da9a6e75476248c4a1eb2b6f052e15f4", "c5c64c5b4cfa4ddcbc7a657b05bb389b", "919977e43d6c460ea725e224e67ed02d", "1aab259a8a1842a88a6a045b64ebd5ba", "f735588658ab48ed8c7f499438e21e60", "ee67032f5c6e473585ff1ec8a94dd254", "cfd7bf43705143088e9af818839757a1", "d93c81dc392842f68243a04847dbc58d", "fb12239db0804b24b6b3be765fd7df67", "7e8043c4a37d49c5ac54c69ffaa35e56", "e8aec710a97f4895b560126105845f97", "4fdb47483d2d4426930abbcffa651731", "94b89f04a3e548fea73094807329be9f", "5de65cb0f48c4d72bf96315de5194380", "8217203c70e041e5b280e85273c03e73", "5cfad843f067462eb536f44898732010", "109415d7ead74c03b004dfc0b1c5fdb7", "0c59d0cc5ea44e9a91647d44222cc071" ] }, "id": "ulMkCsP7IY2K", "outputId": "8aa73adf-f6ae-4742-e84b-b4c092b6cdad" }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "620ee05c533b465ab239668de96407a8", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HTML(value='