-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support image encoder with image caption as example
- Loading branch information
1 parent
5dd0d2c
commit 4542349
Showing
9 changed files
with
198 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"fp16": { | ||
"enabled": false | ||
}, | ||
"bf16": { | ||
"enabled": false | ||
}, | ||
"comms_logger": { | ||
"enabled": false, | ||
"verbose": false, | ||
"prof_all": false, | ||
"debug": false | ||
}, | ||
"steps_per_print": 20000000000000000, | ||
"train_micro_batch_size_per_gpu": 1, | ||
"wall_clock_breakdown": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python | ||
# coding=utf-8 | ||
# Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. | ||
"""A simple shell to inference the input data. | ||
""" | ||
import logging | ||
import json | ||
import os | ||
import sys | ||
sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) | ||
import warnings | ||
|
||
from dataclasses import dataclass, field | ||
from transformers import HfArgumentParser | ||
from typing import Optional | ||
|
||
from lmflow.datasets.dataset import Dataset | ||
from lmflow.pipeline.auto_pipeline import AutoPipeline | ||
from lmflow.models.auto_model import AutoModel | ||
from lmflow.args import ModelArguments, DatasetArguments, AutoArguments | ||
from PIL import Image | ||
import torch | ||
import requests | ||
from transformers import BlipProcessor, BlipForConditionalGeneration | ||
|
||
|
||
logging.disable(logging.ERROR) | ||
warnings.filterwarnings("ignore") | ||
|
||
|
||
def main(): | ||
pipeline_name = "inferencer" | ||
PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) | ||
|
||
parser = HfArgumentParser(( | ||
ModelArguments, | ||
PipelineArguments, | ||
)) | ||
|
||
model_args, pipeline_args = ( | ||
parser.parse_args_into_dataclasses() | ||
) | ||
inferencer_args = pipeline_args | ||
|
||
with open (pipeline_args.deepspeed, "r") as f: | ||
ds_config = json.load(f) | ||
|
||
model = AutoModel.get_model( | ||
model_args, | ||
tune_strategy='none', | ||
ds_config=ds_config, | ||
device=pipeline_args.device, | ||
) | ||
|
||
data_args = DatasetArguments(dataset_path=None) | ||
dataset = Dataset(data_args) | ||
|
||
inferencer = AutoPipeline.get_pipeline( | ||
pipeline_name=pipeline_name, | ||
model_args=model_args, | ||
data_args=data_args, | ||
pipeline_args=pipeline_args, | ||
) | ||
|
||
|
||
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg' | ||
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB') | ||
input_dataset = dataset.from_dict({ | ||
"type": "image_text", | ||
"instances": [{"images": raw_image, | ||
"text": "",}] | ||
}) | ||
|
||
prompt_text = "a photography of" | ||
output = inferencer.inference(model, input_dataset, | ||
prompt_structure=prompt_text + "{input}") | ||
print(output.backend_dataset['text']) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
model="Salesforce/blip-image-captioning-base" | ||
lora_args="" | ||
if [ $# -ge 1 ]; then | ||
model=$1 | ||
fi | ||
if [ $# -ge 2 ]; then | ||
lora_args="--lora_model_path $2" | ||
fi | ||
|
||
CUDA_VISIBLE_DEVICES=7 \ | ||
deepspeed examples/inference.py \ | ||
--deepspeed configs/ds_config_multimodal.json \ | ||
--model_name_or_path ${model} \ | ||
--arch_type visionEncoder_decoder \ | ||
${lora_args} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters