Skip to content

Commit

Permalink
fix qwen-vl example (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
irexyc authored Jan 22, 2024
1 parent 576609f commit 73feadc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion examples/vl/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import os
import random
from contextlib import contextmanager
from dataclasses import dataclass, field
from itertools import count
from pathlib import Path
Expand Down Expand Up @@ -89,12 +90,27 @@ def parse_args():
return args


@contextmanager
def get_stop_words():
from lmdeploy.tokenizer import Tokenizer
old_func = Tokenizer.indexes_containing_token

def new_func(self, token):
indexes = self.encode(token, add_bos=False)
return indexes

Tokenizer.indexes_containing_token = new_func
yield
Tokenizer.indexes_containing_token = old_func


def load_preprocessor_model(args):
"""Load preprocessor and llm inference engine."""
assert args.model_name in SUPPORTED_MODELS
llm_ckpt = args.hf_ckpt if args.llm_ckpt is None else args.llm_ckpt
preprocessor = SUPPORTED_MODELS[args.model_name](args.hf_ckpt)
model = TurboMind.from_pretrained(llm_ckpt, model_name=args.model_name)
with get_stop_words():
model = TurboMind.from_pretrained(llm_ckpt, model_name=args.model_name)
return preprocessor, model


Expand Down

0 comments on commit 73feadc

Please sign in to comment.