chore: import upstream snapshot with attribution
Lint test / lint (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:34:58 +08:00
commit a203934033
1368 changed files with 175001 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
# pip install "transformers==4.46.3" easydict
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
# os.environ['SWIFT_DEBUG'] = '1'
if __name__ == '__main__':
from swift.infer_engine import InferRequest, RequestConfig, TransformersEngine
engine = TransformersEngine('deepseek-ai/DeepSeek-OCR')
infer_request = InferRequest(
messages=[{
'role': 'user',
# or
'content': '<image>Free OCR.',
# "content": '<image><|grounding|>Convert the document to markdown.',
}],
images=['https://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/ocr.png'])
request_config = RequestConfig(max_tokens=512, temperature=0)
resp_list = engine.infer([infer_request], request_config=request_config)
response = resp_list[0].choices[0].message.content
# use stream
request_config = RequestConfig(max_tokens=512, temperature=0, stream=True)
gen_list = engine.infer([infer_request], request_config=request_config)
for chunk in gen_list[0]:
if chunk is None:
continue
print(chunk.choices[0].delta.content, end='', flush=True)
print()
+30
View File
@@ -0,0 +1,30 @@
# 24GiB
pip install "transformers==4.46.3" easydict "peft==0.15.2"
CUDA_VISIBLE_DEVICES=0 \
swift sft \
--model deepseek-ai/DeepSeek-OCR \
--dataset 'AI-ModelScope/LaTeX_OCR:human_handwrite#20000' \
--load_from_cache_file true \
--split_dataset_ratio 0.01 \
--tuner_type lora \
--torch_dtype bfloat16 \
--num_train_epochs 1 \
--per_device_train_batch_size 1 \
--per_device_eval_batch_size 1 \
--learning_rate 1e-4 \
--lora_rank 8 \
--lora_alpha 32 \
--target_modules all-linear \
--freeze_vit true \
--freeze_aligner true \
--gradient_accumulation_steps 16 \
--eval_steps 50 \
--save_steps 50 \
--save_total_limit 2 \
--logging_steps 5 \
--max_length 4096 \
--output_dir output \
--warmup_ratio 0.05 \
--dataset_num_proc 4 \
--dataloader_num_workers 4