-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support MiniCPM3. #9322
Merged
Merged
Support MiniCPM3. #9322
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -1819,6 +1819,60 @@ def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iter | |||||||
return [(self.map_tensor_name(name), data_torch)] | ||||||||
|
||||||||
|
||||||||
@Model.register("MiniCPM3ForCausalLM") | ||||||||
class MiniCPM3Model(Model): | ||||||||
model_arch = gguf.MODEL_ARCH.MINICPM3 | ||||||||
|
||||||||
def set_gguf_parameters(self): | ||||||||
hparams = self.hparams | ||||||||
|
||||||||
rope_dims = hparams["qk_rope_head_dim"] | ||||||||
|
||||||||
self.gguf_writer.add_file_type(self.ftype) | ||||||||
self.gguf_writer.add_context_length(hparams["max_position_embeddings"]) | ||||||||
self.gguf_writer.add_embedding_length(hparams["hidden_size"]) | ||||||||
self.gguf_writer.add_block_count(self.block_count) | ||||||||
self.gguf_writer.add_feed_forward_length(hparams["intermediate_size"]) | ||||||||
self.gguf_writer.add_head_count(hparams["num_attention_heads"]) | ||||||||
self.gguf_writer.add_head_count_kv(hparams["num_key_value_heads"]) | ||||||||
self.gguf_writer.add_layer_norm_rms_eps(hparams["rms_norm_eps"]) | ||||||||
self.gguf_writer.add_vocab_size(hparams["vocab_size"]) | ||||||||
if "q_lora_rank" in hparams and hparams["q_lora_rank"] is not None: | ||||||||
self.gguf_writer.add_q_lora_rank(hparams["q_lora_rank"]) | ||||||||
self.gguf_writer.add_kv_lora_rank(hparams["kv_lora_rank"]) | ||||||||
self.gguf_writer.add_key_length(hparams["qk_nope_head_dim"] + hparams["qk_rope_head_dim"]) | ||||||||
self.gguf_writer.add_rope_dimension_count(hparams["qk_rope_head_dim"]) | ||||||||
|
||||||||
rope_scaling = self.find_hparam(['rope_scaling'], True) | ||||||||
if rope_scaling is None: | ||||||||
return | ||||||||
|
||||||||
long_factors = rope_scaling.get('long_factor', None) | ||||||||
short_factors = rope_scaling.get('short_factor', None) | ||||||||
|
||||||||
if long_factors is None or short_factors is None: | ||||||||
raise KeyError('Missing the required key rope_scaling.long_factor or rope_scaling_short_factor') | ||||||||
|
||||||||
if len(long_factors) != len(short_factors) or len(long_factors) != rope_dims / 2: | ||||||||
raise ValueError(f'The length of rope long and short factors must be {rope_dims / 2}') | ||||||||
|
||||||||
self.gguf_writer.add_tensor(gguf.TENSOR_NAMES[gguf.MODEL_TENSOR.ROPE_FACTORS_LONG] + ".weight", np.array(long_factors, dtype=np.float32)) | ||||||||
self.gguf_writer.add_tensor(gguf.TENSOR_NAMES[gguf.MODEL_TENSOR.ROPE_FACTORS_SHORT] + ".weight", np.array(short_factors, dtype=np.float32)) | ||||||||
|
||||||||
def set_vocab(self): | ||||||||
self._set_vocab_llama_hf() | ||||||||
|
||||||||
def _reverse_hf_permute(self, weights: Tensor, n_head: int, n_kv_head: int | None = None) -> Tensor: | ||||||||
if n_kv_head is not None and n_head != n_kv_head: | ||||||||
n_head //= n_kv_head | ||||||||
|
||||||||
return ( | ||||||||
weights.reshape(n_head, 2, weights.shape[0] // n_head // 2, *weights.shape[1:]) | ||||||||
.swapaxes(1, 2) | ||||||||
.reshape(weights.shape) | ||||||||
) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Lint is also breaking on this -- need to add an additional blank line below your class definition as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your comments. |
||||||||
|
||||||||
|
||||||||
@Model.register("QWenLMHeadModel") | ||||||||
class QwenModel(Model): | ||||||||
model_arch = gguf.MODEL_ARCH.QWEN | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint is currently breaking on this -- need to add an additional blank line above your class definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comments.