--- license: cc-by-nc-4.0 language: - en tags: - vila - nvila - conversational - multimodal --- Dependency setups: ```bash # other transformers version may also work, but we have not tested pip install transformers==4.46 accelerate opencv-python torchvision einops pillow pip install git+https://github.com/bfshi/scaling_on_scales.git ``` ## Usage ```python from transformers import AutoConfig, AutoModel from termcolor import colored model_path = "Efficient-Large-Model/NVILA-Lite-2B-hf-preview" # you can use config config = AutoConfig.from_pretrained(model_path, trust_remote_code=True) model = AutoModel.from_config(config, trust_remote_code=True) # or directly from_pretrained model = AutoModel.from_pretrained(model_path, trust_remote_code=True, device_map="auto") # examples generate with raw text res = model.generate_content([ "how are you today?" ]) print(colored(res, "cyan", attrs=["bold"])) print("---" * 40) # examples generate with text + image import PIL.Image response = model.generate_content([ PIL.Image.open("inference_test/test_data/caption_meat.jpeg"), "describe the image?" ]) print(colored(response, "cyan", attrs=["bold"])) ``` ## AutoProcessor we also support `AutoProcessor` class to ease data preparation for training and finetuning. ### single call ```python from transformers import AutoProcessor, AutoModel model_path = "Efficient-Large-Model/NVILA-Lite-2B-hf-preview" processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True) model = AutoModel.from_pretrained(model_path, trust_remote_code=True, device_map="auto") # important: set model to eval mode, otherwise the model will be in training mode and will pad to right. model.eval() gpt_conv = [{ "role": "user", "content": [ {"type": "image", "path": "https://nvlabs.github.io/VILA/asset/example.jpg"}, {"type": "text", "text": "Describe this image."} ] }] text = processor.apply_chat_template(gpt_conv, tokenize=False, add_generation_prompt=True) inputs = processor([text]) output_ids = model.generate( input_ids=inputs.input_ids, media=inputs.media, media_config=inputs.media_config, generation_config=model.generation_config, max_new_tokens=256, ) print(processor.tokenizer.batch_decode(output_ids, skip_special_tokens=True)) ##### the above code is equivalent to # response = model.generate_content([ # PIL.Image.open("demo_images/demo_img_1.png"), # "describe the image?" # ]) # print(colored(response, "cyan", attrs=["bold"])) ``` ### batch call ```python from transformers import AutoProcessor, AutoModel model_path = "Efficient-Large-Model/NVILA-Lite-2B-hf-preview" model_path = "./NVILA-Lite-2B-hf-preview" processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True) model = AutoModel.from_pretrained(model_path, trust_remote_code=True, device_map="auto") # important: set model to eval mode, otherwise the model will be in training mode and will pad to right. model.eval() gpt_conv1 = [{ "role": "user", "content": [ {"type": "image", "path": "https://nvlabs.github.io/VILA/asset/example.jpg"}, {"type": "text", "text": "Describe this image."} ] }] gpt_conv2 = [{ "role": "user", "content": [ {"type": "image", "path": "https://nvlabs.github.io/VILA/asset/example_vqa.jpg"}, {"type": "text", "text": "Describe this image for me. Provide a detailed description of the image."} ] }] messages = [gpt_conv1, gpt_conv2] texts = [ processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True) for msg in messages ] inputs = processor(texts) output_ids = model.generate( input_ids=inputs.input_ids, media=inputs.media, media_config=inputs.media_config, generation_config=model.generation_config, max_new_tokens=256, ) output_texts = processor.tokenizer.batch_decode(output_ids, skip_special_tokens=True) print(output_texts[0]) print("---" * 40) print(output_texts[1]) ``` ## Model Convert The follwing code converts a convetional NVILA model to a HF compatible model. ```python import os, os.path as osp from transformers import AutoConfig, AutoModel, AutoProcessor, AutoTokenizer, AutoImageProcessor model_path = "Efficient-Large-Model/NVILA-Lite-2B" output_dir = "NVILA-Lite-2B-hf-preview" if osp.isdir(output_dir): shutil.rmtree(output_dir) from llava.remote_code.modeling_vila import VILAForCasualLM VILAForCasualLM.convert_vila_dev_ckpt_to_remote(model_path, output_dir, copy=False) ``` --- license: cc-by-nc-4.0 library_name: transformers pipeline_tag: text-generation tags: - NVILA - VLM --- # VILA Model Card ## Model details **Model type:** NVILA is a visual language model (VLM) pretrained with interleaved image-text data at scale, enabling multi-image VLM. Visual language models (VLMs) have made significant advances in accuracy in recent years. However, their efficiency has received much less attention. This paper introduces NVILA, a family of open VLMs designed to optimize both efficiency and accuracy. Building on top of VILA, we improve its model architecture by first scaling up the spatial and temporal resolutions, and then compressing visual tokens. This "scale-then-compress" approach enables NVILA to efficiently process high-resolution images and long videos. We also conduct a systematic investigation to enhance the efficiency of NVILA throughout its entire lifecycle, from training and fine-tuning to deployment. NVILA matches or surpasses the accuracy of many leading open and proprietary VLMs across a wide range of image and video benchmarks. At the same time, it reduces training costs by 4.5X, fine-tuning memory usage by 3.4X, pre-filling latency by 1.6-2.2X, and decoding latency by 1.2-2.8X. We will soon make our code and models available to facilitate reproducibility. **Model date:** NVILA was trained in Nov 2024. **Paper or resources for more information:** https://github.com/NVLabs/VILA ``` @misc{liu2024nvila, title={NVILA: Efficient Frontier Visual Language Models}, author={Zhijian Liu and Ligeng Zhu and Baifeng Shi and Zhuoyang Zhang and Yuming Lou and Shang Yang and Haocheng Xi and Shiyi Cao and Yuxian Gu and Dacheng Li and Xiuyu Li and Yunhao Fang and Yukang Chen and Cheng-Yu Hsieh and De-An Huang and An-Chieh Cheng and Vishwesh Nath and Jinyi Hu and Sifei Liu and Ranjay Krishna and Daguang Xu and Xiaolong Wang and Pavlo Molchanov and Jan Kautz and Hongxu Yin and Song Han and Yao Lu}, year={2024}, eprint={2412.04468}, archivePrefix={arXiv}, primaryClass={cs.CV}, url={https://arxiv.org/abs/2412.04468}, } ``` ## License - The code is released under the Apache 2.0 license as found in the [LICENSE](./LICENSE) file. - The pretrained weights are released under the [CC-BY-NC-SA-4.0 license](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en). - The service is a research preview intended for non-commercial use only, and is subject to the following licenses and terms: - [Terms of Use](https://openai.com/policies/terms-of-use) of the data generated by OpenAI - [Dataset Licenses](https://github.com/Efficient-Large-Model/VILA/blob/main/data_prepare/LICENSE) for each one used during training. **Where to send questions or comments about the model:** https://github.com/NVLabs/VILA/issues ## Intended use **Primary intended uses:** The primary use of VILA is research on large multimodal models and chatbots. **Primary intended users:** The primary intended users of the model are researchers and hobbyists in computer vision, natural language processing, machine learning, and artificial intelligence. ## Input: **Input Type:** Image, Video, Text **Input Format:** Red, Green, Blue; MP4 ;String **Input Parameters:** 2D, 3D ## Output: **Output Type:** Text **Output Format:** String **Supported Hardware Microarchitecture Compatibility:** * Ampere * Jetson * Hopper * Lovelace **[Preferred/Supported] Operating System(s):**
Linux ## Training dataset See [Dataset Preparation](https://arxiv.org/abs/2412.04468) for more details. ** Data Collection Method by dataset * [Hybrid: Automated, Human] ** Labeling Method by dataset * [Hybrid: Automated, Human] ## Inference: **Engine:** [Tensor(RT), Triton, Or List Other Here] * PyTorch * TensorRT-LLM * TinyChat **Test Hardware:** * A100 * Jetson Orin * RTX 4090 ## Ethical Considerations NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. When downloaded or used in accordance with our terms of service, developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse.