mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-31 08:51:55 +00:00 
			
		
		
		
	convert-lora : make --base optional (#10110)
				
					
				
			* convert-lora : make `--base` optional * lint * handle case where base_model_name_or_path is invalid * do not include metadata from base model * clarify unspecified --base * add small comment [no ci] * trigger ci
This commit is contained in:
		| @@ -72,7 +72,8 @@ class Model: | ||||
|     def __init__(self, dir_model: Path, ftype: gguf.LlamaFileType, fname_out: Path, is_big_endian: bool = False, | ||||
|                  use_temp_file: bool = False, eager: bool = False, | ||||
|                  metadata_override: Path | None = None, model_name: str | None = None, | ||||
|                  split_max_tensors: int = 0, split_max_size: int = 0, dry_run: bool = False, small_first_shard: bool = False): | ||||
|                  split_max_tensors: int = 0, split_max_size: int = 0, dry_run: bool = False, | ||||
|                  small_first_shard: bool = False, hparams: dict[str, Any] | None = None): | ||||
|         if type(self) is Model: | ||||
|             raise TypeError(f"{type(self).__name__!r} should not be directly instantiated") | ||||
|  | ||||
| @@ -87,7 +88,7 @@ class Model: | ||||
|         self.is_safetensors = len(self.part_names) > 0 | ||||
|         if not self.is_safetensors: | ||||
|             self.part_names = Model.get_model_part_names(self.dir_model, "pytorch_model", ".bin") | ||||
|         self.hparams = Model.load_hparams(self.dir_model) | ||||
|         self.hparams = Model.load_hparams(self.dir_model) if hparams is None else hparams | ||||
|         self.block_count = self.find_hparam(["n_layers", "num_hidden_layers", "n_layer", "num_layers"]) | ||||
|         self.tensor_map = gguf.get_tensor_name_map(self.model_arch, self.block_count) | ||||
|         self.tensor_names = None | ||||
| @@ -1541,6 +1542,17 @@ class LlamaModel(Model): | ||||
|             special_vocab._set_special_token("eot",    32010) | ||||
|             special_vocab.add_to_gguf(self.gguf_writer) | ||||
|  | ||||
|         tokenizer_config_file = self.dir_model / 'tokenizer_config.json' | ||||
|         if tokenizer_config_file.is_file(): | ||||
|             with open(tokenizer_config_file, "r", encoding="utf-8") as f: | ||||
|                 tokenizer_config_json = json.load(f) | ||||
|                 if "add_prefix_space" in tokenizer_config_json: | ||||
|                     self.gguf_writer.add_add_space_prefix(tokenizer_config_json["add_prefix_space"]) | ||||
|  | ||||
|         # Apply to granite small models only | ||||
|         if self.hparams.get("vocab_size", 32000) == 49152: | ||||
|             self.gguf_writer.add_add_bos_token(False) | ||||
|  | ||||
|     def set_gguf_parameters(self): | ||||
|         super().set_gguf_parameters() | ||||
|         hparams = self.hparams | ||||
| @@ -1557,17 +1569,6 @@ class LlamaModel(Model): | ||||
|                 self.gguf_writer.add_rope_scaling_type(gguf.RopeScalingType.LINEAR) | ||||
|                 self.gguf_writer.add_rope_scaling_factor(self.hparams["rope_scaling"]["factor"]) | ||||
|  | ||||
|         tokenizer_config_file = self.dir_model / 'tokenizer_config.json' | ||||
|         if tokenizer_config_file.is_file(): | ||||
|             with open(tokenizer_config_file, "r", encoding="utf-8") as f: | ||||
|                 tokenizer_config_json = json.load(f) | ||||
|                 if "add_prefix_space" in tokenizer_config_json: | ||||
|                     self.gguf_writer.add_add_space_prefix(tokenizer_config_json["add_prefix_space"]) | ||||
|  | ||||
|         # Apply to granite small models only | ||||
|         if self.hparams.get("vocab_size", 32000) == 49152: | ||||
|             self.gguf_writer.add_add_bos_token(False) | ||||
|  | ||||
|     @staticmethod | ||||
|     def permute(weights: Tensor, n_head: int, n_head_kv: int | None): | ||||
|         if n_head_kv is not None and n_head != n_head_kv: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Xuan Son Nguyen
					Xuan Son Nguyen