diff --git a/paddlemix/examples/blip2/export.py b/paddlemix/examples/blip2/export.py index d206f4f47..27003f157 100644 --- a/paddlemix/examples/blip2/export.py +++ b/paddlemix/examples/blip2/export.py @@ -11,17 +11,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os import sys - sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")) -import os from dataclasses import dataclass, field +import yaml import paddle -import yaml from paddlenlp.trainer import PdArgumentParser - from paddlemix.models.blip2.modeling import Blip2ForConditionalGeneration from paddlemix.utils.log import logger diff --git a/paddlemix/examples/blip2/merge_weight.py b/paddlemix/examples/blip2/merge_weight.py index 0eeef9754..df675ff4f 100644 --- a/paddlemix/examples/blip2/merge_weight.py +++ b/paddlemix/examples/blip2/merge_weight.py @@ -12,16 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -import argparse import os - -from paddlemix.utils.log import logger +import sys +import argparse +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")) os.environ["CUDA_VISIBLE_DEVICES"] = "0" os.environ["FLAGS_use_cuda_managed_memory"] = "true" import paddle - +from paddlemix.utils.log import logger from paddlenlp.transformers import LlamaForCausalLM from paddlenlp.transformers.opt.modeling import OPTForCausalLM from paddlenlp.transformers.t5.modeling import T5ForConditionalGeneration diff --git a/paddlemix/examples/blip2/run_eval_caption.py b/paddlemix/examples/blip2/run_eval_caption.py index 2158da71b..0f8dc722b 100644 --- a/paddlemix/examples/blip2/run_eval_caption.py +++ b/paddlemix/examples/blip2/run_eval_caption.py @@ -14,19 +14,18 @@ import os import sys - sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")) import random +import numpy as np from dataclasses import dataclass, field -import numpy as np import paddle import paddle.distributed as dist from paddle.distributed import fleet from paddle.distributed.fleet.meta_parallel import get_rng_state_tracker from paddlemix.datasets import load_dataset -from paddlemix.examples.blip2.utils import BlipCollator, create_tokenizer, load_model +from paddlemix.models.blip2.utils import load_model, BlipCollator, create_tokenizer from paddlemix.models.blip2.configuration import Blip2Config from paddlemix.models.blip2.modeling import Blip2ForConditionalGeneration from paddlemix.processors.blip_processing import ( diff --git a/paddlemix/examples/blip2/run_eval_vqav2_zeroshot.py b/paddlemix/examples/blip2/run_eval_vqav2_zeroshot.py index 36ef5356c..ea59ad18c 100644 --- a/paddlemix/examples/blip2/run_eval_vqav2_zeroshot.py +++ b/paddlemix/examples/blip2/run_eval_vqav2_zeroshot.py @@ -14,19 +14,18 @@ import os import sys - sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")) import random +import numpy as np from dataclasses import dataclass, field -import numpy as np import paddle import paddle.distributed as dist from paddle.distributed import fleet from paddle.distributed.fleet.meta_parallel import get_rng_state_tracker from paddlemix.datasets import load_dataset -from paddlemix.examples.blip2.utils import BlipCollator, create_tokenizer, load_model +from paddlemix.models.blip2.utils import load_model, BlipCollator, create_tokenizer from paddlemix.models.blip2.configuration import Blip2Config from paddlemix.models.blip2.modeling import Blip2ForConditionalGeneration from paddlemix.processors.blip_processing import ( @@ -39,6 +38,7 @@ from paddlenlp.trainer import PdArgumentParser, TrainingArguments, get_last_checkpoint + class BlipCollator_VQA(BlipCollator): """ Data collator that will dynamically pad the inputs to the longest sequence in the batch. diff --git a/paddlemix/examples/blip2/run_predict.py b/paddlemix/examples/blip2/run_predict.py index e3c295d8d..ac82aed68 100644 --- a/paddlemix/examples/blip2/run_predict.py +++ b/paddlemix/examples/blip2/run_predict.py @@ -14,20 +14,18 @@ import os import random import sys +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")) +import numpy as np from dataclasses import dataclass, field +import requests +from PIL import Image -import numpy as np import paddle import paddle.distributed as dist from paddle.distributed import fleet from paddle.distributed.fleet.meta_parallel import get_rng_state_tracker -sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")) - -import requests -from PIL import Image - -from paddlemix.examples.blip2.utils import create_tokenizer, load_model +from paddlemix.models.blip2.utils import load_model, create_tokenizer from paddlemix.models.blip2.modeling import Blip2ForConditionalGeneration from paddlemix.processors.blip_processing import ( Blip2Processor, diff --git a/paddlemix/examples/blip2/run_pretrain_stage1.py b/paddlemix/examples/blip2/run_pretrain_stage1.py index 2edd5def9..b1e798ff6 100644 --- a/paddlemix/examples/blip2/run_pretrain_stage1.py +++ b/paddlemix/examples/blip2/run_pretrain_stage1.py @@ -15,20 +15,19 @@ import os import sys import warnings - sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")) import random +import numpy as np from dataclasses import dataclass, field from typing import Optional -import numpy as np import paddle import paddle.distributed as dist from paddle.distributed import fleet from paddle.distributed.fleet.meta_parallel import get_rng_state_tracker from paddlemix.datasets import load_dataset -from paddlemix.examples.blip2.utils import load_model +from paddlemix.models.blip2.utils import load_model from paddlemix.models.blip2.configuration import Blip2Config from paddlemix.models.blip2.modeling import Blip2ForConditionalGeneration from paddlemix.processors.blip_processing import ( diff --git a/paddlemix/examples/blip2/run_pretrain_stage2.py b/paddlemix/examples/blip2/run_pretrain_stage2.py index 5bef44e57..ea76b549a 100644 --- a/paddlemix/examples/blip2/run_pretrain_stage2.py +++ b/paddlemix/examples/blip2/run_pretrain_stage2.py @@ -28,9 +28,9 @@ from paddle.distributed.fleet.meta_parallel import get_rng_state_tracker from paddlemix.datasets import load_dataset -from paddlemix.examples.blip2.utils import BlipCollator, create_tokenizer, load_model from paddlemix.models.blip2.configuration import Blip2Config from paddlemix.models.blip2.modeling import Blip2ForConditionalGeneration +from paddlemix.models.blip2.utils import load_model, BlipCollator, create_tokenizer from paddlemix.processors.blip_processing import ( Blip2Processor, BlipImageProcessor, diff --git a/paddlemix/models/blip2/base_model.py b/paddlemix/models/blip2/base_model.py index 6c97f1477..5f3e00b69 100644 --- a/paddlemix/models/blip2/base_model.py +++ b/paddlemix/models/blip2/base_model.py @@ -21,7 +21,6 @@ import paddle -from paddlemix.examples.blip2.utils import blip2_load from paddlemix.models.model_utils import MixPretrainedModel from paddlemix.utils.log import logger from paddlenlp.transformers import AutoTokenizer @@ -30,6 +29,7 @@ from paddlenlp.utils.env import PADDLE_WEIGHTS_NAME, SAFE_WEIGHTS_NAME from .configuration import Blip2Config +from .utils import blip2_load VISION_WEIGHTS = {"eva_vit_g": "https://bj.bcebos.com/paddlenlp/models/community/paddlemix/blip2-stage2/eva_vit_g"} BRIDGE_WEIGHTS = { diff --git a/paddlemix/examples/blip2/utils.py b/paddlemix/models/blip2/utils.py similarity index 99% rename from paddlemix/examples/blip2/utils.py rename to paddlemix/models/blip2/utils.py index 39825a526..07582347e 100644 --- a/paddlemix/examples/blip2/utils.py +++ b/paddlemix/models/blip2/utils.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import copy import datetime import json @@ -770,4 +771,4 @@ def loadRes(self, resFile, quesFile): res.dataset["annotations"] = anns res.createIndex() - return res + return res \ No newline at end of file