Update README.md
Browse files
README.md
CHANGED
|
@@ -12,4 +12,63 @@ See detail at our [Project Page](https://github.com/TongUI-agent/TongUI-agent)
|
|
| 12 |
|
| 13 |
## Model Details
|
| 14 |
|
| 15 |
-
The base model is `Qwen/Qwen2.5-VL-32B-Instruct`. We fine-tuned base model by Lora.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
## Model Details
|
| 14 |
|
| 15 |
+
The base model is `Qwen/Qwen2.5-VL-32B-Instruct`. We fine-tuned base model by Lora.
|
| 16 |
+
|
| 17 |
+
**Note:** Due to large size of 32B model, we only release the LoRA part of this model. To merge the weights, use the following script:
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration, AutoConfig, AutoModelForImageTextToText
|
| 21 |
+
import torch
|
| 22 |
+
from peft.peft_model import PeftModel
|
| 23 |
+
|
| 24 |
+
def load_model_and_processor(model_path, precision="bf16", lora_path=None, merge_lora=True):
|
| 25 |
+
"""
|
| 26 |
+
Load the Qwen2.5-VL model and processor with optional LoRA weights.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
args: Arguments containing:
|
| 30 |
+
- model_path: Path to the base model
|
| 31 |
+
- precision: Model precision ("fp16", "bf16", or "fp32")
|
| 32 |
+
- lora_path: Path to LoRA weights (optional)
|
| 33 |
+
- merge_lora: Boolean indicating whether to merge LoRA weights
|
| 34 |
+
|
| 35 |
+
Returns:
|
| 36 |
+
tuple: (processor, model) - The initialized processor and model
|
| 37 |
+
"""
|
| 38 |
+
# Initialize processor
|
| 39 |
+
try:
|
| 40 |
+
processor = AutoProcessor.from_pretrained(
|
| 41 |
+
model_path
|
| 42 |
+
)
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"Error loading processor: {e}")
|
| 45 |
+
processor = None
|
| 46 |
+
config = AutoConfig.from_pretrained(model_path)
|
| 47 |
+
print(config)
|
| 48 |
+
raise e
|
| 49 |
+
# Initialize base model
|
| 50 |
+
from transformers import Qwen2_5_VLForConditionalGeneration
|
| 51 |
+
# Initialize base model
|
| 52 |
+
model_cls = Qwen2_5_VLForConditionalGeneration
|
| 53 |
+
model = model_cls.from_pretrained(
|
| 54 |
+
model_path,
|
| 55 |
+
device_map="auto",
|
| 56 |
+
torch_dtype=torch.float16 if precision == "fp16" else torch.bfloat16 if precision == "bf16" else torch.float32,
|
| 57 |
+
attn_implementation="flash_attention_2",
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Load LoRA weights if path is provided
|
| 61 |
+
if lora_path is not None and len(lora_path) > 0:
|
| 62 |
+
print(f"Loading LoRA weights from {lora_path}")
|
| 63 |
+
model = PeftModel.from_pretrained(model, lora_path)
|
| 64 |
+
|
| 65 |
+
if merge_lora:
|
| 66 |
+
print("Merging LoRA weights into base model")
|
| 67 |
+
model = model.merge_and_unload()
|
| 68 |
+
|
| 69 |
+
model.eval()
|
| 70 |
+
|
| 71 |
+
return processor, model
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
`model_path` is the base model, and `lora_path` is where you download this repo.
|