代码拉取完成,页面将自动刷新
同步操作将从 Ascend/MindSpeed-MM 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import torch
from PIL import Image
from transformers import CLIPImageProcessor
import mindspeed.megatron_adaptor
from megatron.training import get_args
from mindspeed_mm.data.data_utils.constants import MODEL_CONSTANTS
from mindspeed_mm.utils.utils import get_dtype
from mindspeed_mm.tasks.inference.pipeline.llava_pipeline import LlavaPipeline
from mindspeed_mm.configs.config import mm_extra_args_provider
from mindspeed_mm.models.text_encoder import Tokenizer
from pretrain_llava import model_provider
def load_models(args):
tokenizer = Tokenizer(args.mm.model.tokenizer).get_tokenizer()
model = model_provider()
tokenizer.add_tokens([MODEL_CONSTANTS["llava"]["IMAGE_PATCH_TOKEN"]], special_tokens=True)
image_processor = CLIPImageProcessor.from_pretrained(args.mm.model.image_processer_path)
model.to(dtype=args.mm.model.dtype, device=torch.device(args.mm.model.device))
return tokenizer, model, image_processor
def load_image(image_file):
image = Image.open(image_file).convert('RGB')
return [image]
class main():
from megatron.training.initialize import initialize_megatron
from mindspeed_mm.configs.config import merge_mm_args
initialize_megatron(
extra_args_provider=mm_extra_args_provider, args_defaults={'tokenizer_type': 'GPT2BPETokenizer'}
)
args = get_args()
merge_mm_args(args)
tokenizer, model, image_processor = load_models(args)
llava_pipeline = LlavaPipeline(tokenizer, model, image_processor, args)
image = load_image(args.mm.model.image_path)
dtype = get_dtype(args.mm.model.dtype)
llava_pipeline(args.mm.model.prompts, image, args.mm.model.device, dtype)
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。