(args)
| 99 | |
| 100 | |
| 101 | def load(args): |
| 102 | # define the model |
| 103 | misc.init_distributed_mode(args) |
| 104 | fs_init.initialize_model_parallel(args.model_parallel_size) |
| 105 | model = MetaModel(args.llama_type, args.llama_config, args.tokenizer_path, with_visual=True) |
| 106 | print(f"load pretrained from {args.pretrained_path}") |
| 107 | load_tensor_parallel_model_list(model, args.pretrained_path) |
| 108 | |
| 109 | if args.quant: |
| 110 | print("Quantizing model to 4bit!") |
| 111 | |
| 112 | from transformers.utils.quantization_config import BitsAndBytesConfig |
| 113 | quantization_config = BitsAndBytesConfig.from_dict( |
| 114 | config_dict={ |
| 115 | "load_in_8bit": False, |
| 116 | "load_in_4bit": True, |
| 117 | "bnb_4bit_quant_type": "nf4", |
| 118 | }, |
| 119 | return_unused_kwargs=False, |
| 120 | ) |
| 121 | quantize(model, quantization_config) |
| 122 | |
| 123 | #print("Model = %s" % str(model)) |
| 124 | model.bfloat16().cuda() |
| 125 | return model |
| 126 | |
| 127 | |
| 128 | @ torch.inference_mode() |
no test coverage detected