(args)
| 87 | return chunks[k] |
| 88 | |
| 89 | def load(args): |
| 90 | # define the model |
| 91 | misc.init_distributed_mode(args) |
| 92 | fs_init.initialize_model_parallel(args.model_parallel_size) |
| 93 | model = MetaModel(args.llama_type, args.llama_config, args.tokenizer_path, with_visual=True) |
| 94 | print(f"load pretrained from {args.pretrained_path}") |
| 95 | load_tensor_parallel_model_list(model, args.pretrained_path) |
| 96 | |
| 97 | if args.quant: |
| 98 | print("Quantizing model to 4bit!") |
| 99 | |
| 100 | from transformers.utils.quantization_config import BitsAndBytesConfig |
| 101 | quantization_config = BitsAndBytesConfig.from_dict( |
| 102 | config_dict={ |
| 103 | "load_in_8bit": False, |
| 104 | "load_in_4bit": True, |
| 105 | "bnb_4bit_quant_type": "nf4", |
| 106 | }, |
| 107 | return_unused_kwargs=False, |
| 108 | ) |
| 109 | quantize(model, quantization_config) |
| 110 | |
| 111 | print("Model = %s" % str(model)) |
| 112 | model.bfloat16().cuda() |
| 113 | return model |
| 114 | |
| 115 | @ torch.inference_mode() |
| 116 | def generate_output(model, img_path, prompt): |
no test coverage detected