(args)
| 80 | |
| 81 | # load model and tokenizer |
| 82 | def load(args): |
| 83 | |
| 84 | # define the model |
| 85 | misc.init_distributed_mode(args) |
| 86 | fs_init.initialize_model_parallel(args.model_parallel_size) |
| 87 | model = MetaModel(args.llama_type, args.llama_config, args.tokenizer_path, with_visual=True) |
| 88 | print(f"load pretrained from {args.pretrained_path}") |
| 89 | load_tensor_parallel_model_list(model, args.pretrained_path) |
| 90 | |
| 91 | if args.quant: |
| 92 | print("Quantizing model to 4bit!") |
| 93 | |
| 94 | from transformers.utils.quantization_config import BitsAndBytesConfig |
| 95 | quantization_config = BitsAndBytesConfig.from_dict( |
| 96 | config_dict={ |
| 97 | "load_in_8bit": False, |
| 98 | "load_in_4bit": True, |
| 99 | "bnb_4bit_quant_type": "nf4", |
| 100 | }, |
| 101 | return_unused_kwargs=False, |
| 102 | ) |
| 103 | quantize(model, quantization_config) |
| 104 | |
| 105 | #print("Model = %s" % str(model)) |
| 106 | model.bfloat16().cuda() |
| 107 | return model |
| 108 | |
| 109 | def extract_ans(ans): |
| 110 | ans = ans.strip() |
no test coverage detected