Skip to content
TheChatArchiveThe Chat Archive
gpt-4-1106-preview· openaiHugging Face Suzhen/CodeChat

Fais moi un script Colab pour entraîner ce modèle Code Pull requests 5 Security Insights…

  1. User

    Fais moi un script Colab pour entraîner ce modèle Code Pull requests 5 Security Insights apple/ml-ferret 1 branch 0 tags Latest commit @Haotian-Zhang Haotian-Zhang checkpoints release 262a943 3 weeks ago Git stats 3 commits Files Type Name Latest commit message Commit time experiments first code commit 3 months ago ferret checkpoints release 3 weeks ago figs first code commit 3 months ago scripts checkpoints release 3 weeks ago CODE_OF_CONDUCT.md first commit 3 months ago CONTRIBUTING.md first code commit 3 months ago EVAL.md first code commit 3 months ago LICENSE first commit 3 months ago README.md checkpoints release 3 weeks ago pyproject.toml first code commit 3 months ago README.md Alt text for the image Ferret: Refer and Ground Anything Anywhere at Any Granularity

    An End-to-End MLLM that Accept Any-Form Referring and Ground Anything in Response. [Paper]

    Haoxuan You*, Haotian Zhang*, Zhe Gan, Xianzhi Du, <PRESIDIO_ANONYMIZED_PERSON>, <PRESIDIO_ANONYMIZED_PERSON>, Liangliang Cao, Shih-Fu Chang, Yinfei Yang [*: equal contribution]

    Overview

    Diagram of Ferret Model.

    Key Contributions:

    Ferret Model - Hybrid Region Representation + Spatial-aware Visual Sampler enable fine-grained and open-vocabulary referring and grounding in MLLM. GRIT Dataset (~1.1M) - A Large-scale, Hierarchical, Robust ground-and-refer instruction tuning dataset. Ferret-Bench - A multimodal evaluation benchmark that jointly requires Referring/Grounding, Semantics, Knowledge, and Reasoning. Release

    [12/14] 🔥 We released the checkpoints(7B, 13B). [10/30] 🔥 We released the code of FERRET model and Ferret-Bench. Usage and License Notices: The data, and code is intended and licensed for research use only. They are also restricted to uses that follow the license agreement of LLaMA, Vicuna and GPT-4. The dataset is CC BY NC 4.0 (allowing only non-commercial use) and models trained using the dataset should not be used outside of research purposes.

    Contents

    Install Train Evaluation Demo Install

    Clone this repository and navigate to FERRET folder git clone https://github.com/apple/ml-ferret cd ml-ferret Install Package conda create -n ferret python=3.10 -y conda activate ferret pip install --upgrade pip # enable PEP 660 support pip install -e . pip install pycocotools pip install protobuf==3.20.0 Install additional packages for training cases pip install ninja pip install flash-attn --no-build-isolation Train

    FERRET is trained on 8 A100 GPUs with 80GB memory. To train on fewer GPUs, you can reduce the per_device_train_batch_size and increase the gradient_accumulation_steps accordingly. Always keep the global batch size the same: per_device_train_batch_size x gradient_accumulation_steps x num_gpus.

    Hyperparameters

    We use a similar set of hyperparameters as LLaVA(Vicuna) in finetuning.

    Hyperparameter Global Batch Size Learning rate Epochs Max length Weight decay FERRET-7B 128 2e-5 3 2048 0 FERRET-13B 128 2e-5 3 2048 0 Prepare Vicuna checkpoint and LLaVA's projector

    Before you start, prepare our base model Vicuna, which is an instruction-tuned chatbot. Please download its weights following the instructions here. Vicuna v1.3 is used in FERRET.

    Then download LLaVA's first-stage pre-trained projector weight (7B, 13B).

    FERRET Training

    The scripts are provided (7B, 13B).

    Evaluation

    Please see this doc for the details.

    Checkpoints

    We extracted the delta between our pre-trained model and Vicuna. Please first download weights of Vicuna following the previous instruction. Then download our prepared offsets of weights: 7B, 13B using wget or curl, and unzip the downloaded offsets. Lastly, apply the offset to the Vicuna's weight by running the following script:

    7B

    python3 -m ferret.model.apply_delta
    --base ./model/vicuna-7b-v1-3
    --target ./model/ferret-7b-v1-3
    --delta path/to/ferret-7b-delta

    13B

    python3 -m ferret.model.apply_delta
    --base ./model/vicuna-13b-v1-3
    --target ./model/ferret-13b-v1-3
    --delta path/to/ferret-13b-delta Notices: Apple's rights in the attached weight differentials are hereby licensed under the CC-BY-NC license. Apple makes no representations with regards to LLaMa or any other third party software, which are subject to their own terms.

    Please refer to the next section about how to set up a local demo with pre-trained weight.

    Demo

    To run our demo, you need to train FERRET and use the checkpoints locally. Gradio web UI is used. Please run the following commands one by one.

    Launch a controller

    python -m ferret.serve.controller --host 0.0.0.0 --port 10000 Launch a gradio web server.

    python -m ferret.serve.gradio_web_server --controller http://localhost:10000 --model-list-mode reload --add_region_feature Launch a model worker

    This is the worker that load the ckpt and do the inference on the GPU. Each worker is responsible for a single model specified in --model-path.

    CUDA_VISIBLE_DEVICES=0 python -m ferret.serve.model_worker --host 0.0.0.0 --controller http://localhost:10000 --port 40000 --worker http://localhost:40000 --model-path ./checkpoints/FERRET-13B-v0 --add_region_feature Wait until the process finishes loading the model and you see "Uvicorn running on ...". Now, refresh your Gradio web UI, and you will see the model you just launched in the model list.

    Example of Ferret Interactive Demo.

    Citation

    If you find Ferret useful, please cite using this BibTeX:

    @article{you2023ferret, title={Ferret: Refer and Ground Anything Anywhere at Any Granularity}, author={You, Haoxuan and Zhang, Haotian and Gan, Zhe and Du, Xianzhi and Zhang, Bowen and Wang, Zirui and Cao, Liangliang and Chang, Shih-Fu and Yang, Yinfei}, journal={arXiv preprint arXiv:2310.07704}, year={2023} } Acknowledgement

    LLaVA: the codebase we built upon. Vicuna: the LLM codebase.

  2. Assistant

    Avant de commencer, je tiens à souligner quelques prérequis importants. Veuillez vous assurer que vous avez suivi toutes les lignes directrices relatives aux licences, en particulier en ce qui concerne l'utilisation de modèles comme Vicuna et LLaVA, ainsi que les instructions sur la façon d'obtenir ces modèles. De plus, cet exemple de script assume que vous travaillez sur un système avec des ressources matérielles suffisantes, telles que des cartes graphiques NVIDIA A100, comme mentionné pour la formation du modèle.

    Voici un exemple de script Google Colab que vous pouvez utiliser pour configurer l'environnement et commencer à entraîner le modèle FERRET. Assurez-vous de suivre les instructions concernant les poids de Vicuna et les delta weights correctement avant de lancer ce script.

    # Indiquez d'abord à Colab d'utiliser un GPU
    from google.colab import drive
    drive.mount('/content/drive')
    
    # Vérifiez si un GPU est disponible et installez Miniconda
    import torch
    
    if not torch.cuda.is_available():
        raise SystemError("GPU device not found")
    
    print('GPU found :)', torch.cuda.get_device_name(0))
    
    !wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
    !chmod +x Miniconda3-latest-Linux-x86_64.sh
    !bash ./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local
    
    # Ajoutez conda dans le chemin et créez un nouvel environnement conda
    import sys
    sys.path.append('/usr/local/lib/python3.7/site-packages/')
    !conda create -n ferret python=3.10 -y
    
    # Activer l'environnement conda et installer les dépendances
    %%bash
    source /usr/local/etc/profile.d/conda.sh
    conda activate ferret
    
    pip install --upgrade pip
    pip install ninja
    pip install pycocotools==2.0.4
    pip install protobuf==3.20.0
    pip install flash-attn --no-build-isolation
    
    # Clonez le dépôt ml-ferret et naviguez vers le dossier ml-ferret
    !git clone https://github.com/apple/ml-ferret
    %cd ml-ferret
    
    # Installez le paquet ml-ferret
    !pip install -e .
    
    # (Note: Les étapes pour télécharger les pondérations et deltas de Vicuna ne sont pas incluses ici, 
    # suivez les instructions de la section "Release" du README du dépôt pour ces étapes.)
    
    # Configuration des variables d'environnement pour utiliser le GPU
    import os
    os.environ['CUDA_VISIBLE_DEVICES'] = '0'
    
    # Train the FERRET model - vous devrez modifier les chemins de fichier et les hyperparamètres selon votre setup
    %%bash
    source /usr/local/etc/profile.d/conda.sh
    conda activate ferret
    
    # Exemple de script pour entraîner le modèle FERRET-7B.
    # Vous aurez besoin de spécifier les chemins et hyperparamètres corrects.
    # Les chemins ci-dessous sont des remplissages et doivent être ajustées à votre configuration
    # Exemple de commande pour démarrer l'entraînement.
    # Vous devrez probablement adapter les hyperparamètres et les chemins selon votre environnement spécifique.
    
    python3 -m ferret.main.init \
        --model-path "chemin/vers/vicuna-7b-v1-3" \
        --max-train-steps 1000 \
        --batch-size 32 \
        --learning-rate 2e-5 \
        --max-length 2048 \
        --gradient-accumulation-steps 4
    

    Assurez-vous que toutes les variables de chemin et les options sont correctement définies avant d'exécuter ce script. De plus, en fonction de la mémoire disponible sur votre GPU Colab, vous devrez peut-être ajuster la taille des lots (--batch-size) et les étapes d'accumulation de gradient (--gradient-accumulation-steps) pour que l'entraînement se déroule sans problème.

    En raison de limitations potentielles de Colab et de la nécessité d'obtenir et de gérer les grands modèles de données (comme Vicuna), il pourrait être nécessaire de passer à un environnement avec plus de ressources, comme une instance de cloud disposant de GPU plus puissants. De plus, ce script est un exemple simplifié et ne prend pas en compte tous les aspects du processus de configuration et de formation complet, qui peut inclure des étapes supplémentaires non mentionnées ici.