Qwen VL - Pytorch
Project description
Qwen-VL
My personal implementation of the model from "Qwen-VL: A Frontier Large Vision-Language Model with Versatile Abilities", they haven't released model code yet sooo...
Install
pip3 install qwen
Usage
import torch
from qwen.model import QwenVL
#usage
img = torch.randn(1, 3, 256, 256)
caption = torch.randint(0, 20000, (1, 1024))
model = QwenVL()
output = model(img, caption)
print(output.shape)
Inference
from qwen.inference import QwenVLChat
qwen_chat = QwenVLChat(model_name="Qwen/Qwen-VL-Chat", device_map="cuda")
response = qwen_chat.chat([
{"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"},
{"text": "这是什么?"}
])
print(response)
Training
from qwen.train import Train
def train():
os.environ['MASTER_ADDR'] #'localhost'
os.environ['MASTER_PORT'] #= '9994'
# # [CRITICAL] Pay attention to this when scaling to multiple GPUs and clusters
os.environ['RANK'] #= str(0) # Number of nodes (servers)
os.environ['WORLD_SIZE'] # = str(torch.cuda.device_count())
dist.init_process_group(backend='nccl') #init_method="env://")
Train()
if __name__ == '__main__':
train()
-
Set the environment variables:
ENTITY_NAME
: Your wandb project nameOUTPUT_DIR
: Directory to save the weights (e.g.,./weights
)MASTER_ADDR
: For distributed trainingMASTER_PORT
For master port distributed trainingRANK
- Number of nodes servicesWORLD_SIZE
Number of gpus
-
Configure the training:
- Accelerate Config
- Enable Deepspeed 3
- Accelerate launch train_distributed_accelerate.py
For more information, refer to the Training SOP.
Todo
-
Position aware vision language adapter, compresses image features. Singer layer cross attention module inited randomly => group of trainable embeddings as query vectors + image features from the visual encoder as keys for cross attention ops => OUTPUT: compresses visual feature sequence to a fixed lnegth of 256, 2d absolute positional encodings are integrated into the cross attentions mechanisms query key pairs => compressed feature sequence of length of 256 => fed into decoder llm
-
Bounding Boxes, for any given accurate bounding box, a norm process is applied in the range [0, 1000] and transformed into a string format (Xtope, Ytople)(Xottomright, Ybottomright) -> the string is tokenized as text and does not require positional vocabulary. Detection strings and regular text strings, two special tokens and are added to the beginning and end of the bounding box string. + another sed of special tokens ( and ) is introduced.
Citations
Please use the following to cite this work:
@article{bai2023qwen,
title={Qwen-VL: A Frontier Large Vision-Language Model with Versatile Abilities},
author={Bai, Jinze and Bai, Shuai and Yang, Shusheng and Wang, Shijie and Tan, Sinan and Wang, Peng and Lin, Junyang and Zhou, Chang and Zhou, Jingren},
journal={arXiv preprint arXiv:2308.12966},
year={2023},
url={https://doi.org/10.48550/arXiv.2308.12966}
}
For more details, please refer to the full paper.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file qwen-0.1.0.tar.gz
.
File metadata
- Download URL: qwen-0.1.0.tar.gz
- Upload date:
- Size: 31.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.0 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa96c95c95362ac18008608a834281e2b9a003f16ea13ad639c4f45fae8893d9 |
|
MD5 | 77e89ec1306ce86e0cd4757b51b5cdd1 |
|
BLAKE2b-256 | 8a30c9529affee9298c50bdae1454b43935e3e34f269296d6ef08522771ccb97 |
File details
Details for the file qwen-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: qwen-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.0 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6828d822e9c987f33d4973f7766dc796a7ea9c1bbb750d6e12faab61524acb1c |
|
MD5 | 381145870c2e39a628b4f168e623fa78 |
|
BLAKE2b-256 | 86b9f1a8064ac86aa62c7861352ecf03e779bdb3fd3d0a3fe88027fff785fad3 |