(args)
| 52 | |
| 53 | # load model and tokenizer |
| 54 | def load(args): |
| 55 | |
| 56 | # define the model |
| 57 | misc.init_distributed_mode(args) |
| 58 | fs_init.initialize_model_parallel(args.model_parallel_size) |
| 59 | model = MetaModel(args.llama_type, args.llama_config, args.tokenizer_path, with_visual=True) |
| 60 | print(f"load pretrained from {args.pretrained_path}") |
| 61 | load_tensor_parallel_model_list(model, args.pretrained_path) |
| 62 | |
| 63 | if args.quant: |
| 64 | print("Quantizing model to 4bit!") |
| 65 | |
| 66 | from transformers.utils.quantization_config import BitsAndBytesConfig |
| 67 | quantization_config = BitsAndBytesConfig.from_dict( |
| 68 | config_dict={ |
| 69 | "load_in_8bit": False, |
| 70 | "load_in_4bit": True, |
| 71 | "bnb_4bit_quant_type": "nf4", |
| 72 | }, |
| 73 | return_unused_kwargs=False, |
| 74 | ) |
| 75 | quantize(model, quantization_config) |
| 76 | |
| 77 | #print("Model = %s" % str(model)) |
| 78 | model.bfloat16().cuda() |
| 79 | return model |
| 80 | |
| 81 | def is_number(s): |
| 82 | try: |
no test coverage detected