This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
from swift import BaseArguments, InferRequest, TransformersEngine, get_template
|
||||
|
||||
os.environ['IMAGE_MAX_TOKEN_NUM'] = '1024'
|
||||
os.environ['VIDEO_MAX_TOKEN_NUM'] = '128'
|
||||
os.environ['FPS_MAX_FRAMES'] = '16'
|
||||
|
||||
infer_request = InferRequest(
|
||||
messages=[{
|
||||
'role':
|
||||
'user',
|
||||
'content':
|
||||
"多标签分类,类别包括:['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', "
|
||||
"'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', "
|
||||
"'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']"
|
||||
}],
|
||||
images=['xxx.jpg'])
|
||||
adapter_path = 'output/vx-xxx/checkpoint-xxx'
|
||||
args = BaseArguments.from_pretrained(adapter_path)
|
||||
|
||||
engine = TransformersEngine(
|
||||
args.model,
|
||||
adapters=[adapter_path],
|
||||
task_type='seq_cls',
|
||||
num_labels=args.num_labels,
|
||||
problem_type=args.problem_type)
|
||||
template = get_template(
|
||||
engine.processor, args.system, template_type=args.template, use_chat_template=args.use_chat_template)
|
||||
engine.template = template
|
||||
|
||||
resp_list = engine.infer([infer_request])
|
||||
response: List[int] = resp_list[0].choices[0].message.content
|
||||
print(f'response: {response}')
|
||||
@@ -0,0 +1,7 @@
|
||||
CUDA_VISIBLE_DEVICES=0 \
|
||||
IMAGE_MAX_TOKEN_NUM=1024 \
|
||||
VIDEO_MAX_TOKEN_NUM=128 \
|
||||
FPS_MAX_FRAMES=16 \
|
||||
swift infer \
|
||||
--adapters output/vx-xxx/checkpoint-xxx \
|
||||
--load_data_args true
|
||||
@@ -0,0 +1,30 @@
|
||||
# Custom dataset format reference: https://swift.readthedocs.io/en/latest/Customization/Custom-dataset.html
|
||||
CUDA_VISIBLE_DEVICES=0 \
|
||||
swift sft \
|
||||
--model Qwen/Qwen2.5-0.5B \
|
||||
--tuner_type lora \
|
||||
--dataset '<your-dataset>' \
|
||||
--load_from_cache_file true \
|
||||
--split_dataset_ratio 0.01 \
|
||||
--torch_dtype bfloat16 \
|
||||
--num_train_epochs 1 \
|
||||
--per_device_train_batch_size 16 \
|
||||
--per_device_eval_batch_size 16 \
|
||||
--learning_rate 1e-4 \
|
||||
--lora_rank 8 \
|
||||
--lora_alpha 32 \
|
||||
--target_modules all-linear \
|
||||
--gradient_accumulation_steps 1 \
|
||||
--eval_steps 100 \
|
||||
--save_steps 100 \
|
||||
--save_total_limit 2 \
|
||||
--logging_steps 5 \
|
||||
--max_length 2048 \
|
||||
--output_dir output \
|
||||
--warmup_ratio 0.05 \
|
||||
--dataloader_num_workers 4 \
|
||||
--dataset_num_proc 4 \
|
||||
--num_labels '<num-labels>' \
|
||||
--task_type seq_cls \
|
||||
--use_chat_template false \
|
||||
--problem_type multi_label_classification
|
||||
@@ -0,0 +1,31 @@
|
||||
CUDA_VISIBLE_DEVICES=0 \
|
||||
IMAGE_MAX_TOKEN_NUM=1024 \
|
||||
VIDEO_MAX_TOKEN_NUM=128 \
|
||||
FPS_MAX_FRAMES=16 \
|
||||
swift sft \
|
||||
--model Qwen/Qwen3-VL-4B-Instruct \
|
||||
--tuner_type lora \
|
||||
--dataset 'clip-benchmark/wds_voc2007_multilabel' \
|
||||
--load_from_cache_file true \
|
||||
--split_dataset_ratio 0.01 \
|
||||
--torch_dtype bfloat16 \
|
||||
--num_train_epochs 2 \
|
||||
--per_device_train_batch_size 16 \
|
||||
--per_device_eval_batch_size 16 \
|
||||
--learning_rate 1e-4 \
|
||||
--lora_rank 8 \
|
||||
--lora_alpha 32 \
|
||||
--target_modules all-linear \
|
||||
--gradient_accumulation_steps 1 \
|
||||
--eval_steps 100 \
|
||||
--save_steps 100 \
|
||||
--save_total_limit 2 \
|
||||
--logging_steps 5 \
|
||||
--max_length 2048 \
|
||||
--output_dir output \
|
||||
--warmup_ratio 0.05 \
|
||||
--dataloader_num_workers 4 \
|
||||
--dataset_num_proc 4 \
|
||||
--num_labels 20 \
|
||||
--task_type seq_cls \
|
||||
--problem_type multi_label_classification
|
||||
Reference in New Issue
Block a user