jetmoe
mindnlp.transformers.models.jetmoe.configuration_jetmoe
¶
JetMoE model configuration
mindnlp.transformers.models.jetmoe.configuration_jetmoe.JetMoEConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [JetMoEModel
]. It is used to instantiate an
JetMoE model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a configuration of the JetMoE-4B.
Configuration objects inherit from [PretrainedConfig
] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig
] for more information.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
Vocabulary size of the JetMoE model. Defines the number of different tokens that can be represented by the
TYPE:
|
hidden_size |
Dimension of the hidden representations.
TYPE:
|
num_hidden_layers |
Defines the number of blocks.
TYPE:
|
num_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
num_key_value_heads |
Number of attention heads for each key and value in the Transformer encoder.
TYPE:
|
kv_channels |
Defines the number of channels for the key and value tensors.
TYPE:
|
ffn_hidden_size |
Defines the hidden size of the feed-forward layer.
TYPE:
|
max_position_embeddings |
The maximum sequence length that this model might ever be used with. JetMoE's sliding window attention allows sequence of up to 4096*32 tokens.
TYPE:
|
activation_function |
Defines the activation function for MLP experts.
TYPE:
|
glu |
Whether to use Gated Linear Units in the MLP experts.
TYPE:
|
moe_num_experts |
Defines the number of experts in the mixture of experts.
TYPE:
|
moe_top_k |
Defines the number of experts to use for each token.
TYPE:
|
use_cache |
Whether or not the model should return the last key/values attentions (not used by all models). Only
relevant if
TYPE:
|
bos_token_id |
The id of the "beginning-of-sequence" token.
TYPE:
|
eos_token_id |
The id of the "end-of-sequence" token.
TYPE:
|
tie_word_embeddings |
Whether the model's input and output word embeddings should be tied.
TYPE:
|
bias |
Whether to use bias in the feed-forward and attention layer.
TYPE:
|
rope_theta |
The base period of the RoPE embeddings.
TYPE:
|
rms_norm_eps |
The epsilon used by the rms normalization layers.
TYPE:
|
initializer_range |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
Example
>>> from transformers import JetMoEModel, JetMoEConfig
...
>>> # Initializing a JetMoE 4B style configuration
>>> configuration = JetMoEConfig()
...
>>> # Initializing a model from the JetMoE 4B style configuration
>>> model = JetMoEModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/jetmoe/configuration_jetmoe.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
mindnlp.transformers.models.jetmoe.configuration_jetmoe.JetMoEConfig.__init__(vocab_size=32000, hidden_size=2048, num_hidden_layers=12, num_attention_heads=32, num_key_value_heads=16, kv_channels=128, ffn_hidden_size=5632, max_position_embeddings=4096, activation_function='silu', glu=True, moe_num_experts=8, moe_top_k=2, use_cache=True, bos_token_id=1, eos_token_id=2, tie_word_embeddings=True, bias=True, rope_theta=10000.0, rms_norm_eps=1e-06, initializer_range=0.01, **kwargs)
¶
init
Initializes a new instance of JetMoEConfig.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
vocab_size |
The size of the vocabulary. Defaults to 32000.
TYPE:
|
hidden_size |
The size of the hidden layers. Defaults to 2048.
TYPE:
|
num_hidden_layers |
The number of hidden layers. Defaults to 12.
TYPE:
|
num_attention_heads |
The number of attention heads. Defaults to 32.
TYPE:
|
num_key_value_heads |
The number of key-value heads. Defaults to 16.
TYPE:
|
kv_channels |
The number of channels for key and value computation. Defaults to 128.
TYPE:
|
ffn_hidden_size |
The size of the feed-forward network hidden layers. Defaults to 5632.
TYPE:
|
max_position_embeddings |
The maximum position for positional embeddings. Defaults to 4096.
TYPE:
|
activation_function |
The activation function to be used. Defaults to 'silu'.
TYPE:
|
glu |
Whether to use Gated Linear Unit (GLU). Defaults to True.
TYPE:
|
moe_num_experts |
The number of experts for Mixture of Experts (MoE). Defaults to 8.
TYPE:
|
moe_top_k |
The top K experts to be used in MoE. Defaults to 2.
TYPE:
|
use_cache |
Whether to use cache for decoding. Defaults to True.
TYPE:
|
bos_token_id |
The ID of the beginning of sequence token. Defaults to 1.
TYPE:
|
eos_token_id |
The ID of the end of sequence token. Defaults to 2.
TYPE:
|
tie_word_embeddings |
Whether to tie word embeddings. Defaults to True.
TYPE:
|
bias |
Whether to use bias. Defaults to True.
TYPE:
|
rope_theta |
The theta value for Relative Positional Embeddings (RoPE). Defaults to 10000.0.
TYPE:
|
rms_norm_eps |
The epsilon value for RMSNorm. Defaults to 1e-06.
TYPE:
|
initializer_range |
The range for weight initialization. Defaults to 0.01.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/jetmoe/configuration_jetmoe.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe
¶
MindSpore JetMoE model.
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEAttention
¶
Bases: Module
Multi-headed attention from 'Attention Is All You Need' paper.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEAttention.__init__(config, layer_idx=None)
¶
Initialize the JetMoEAttention module.
PARAMETER | DESCRIPTION |
---|---|
config |
Configuration object with model hyperparameters.
TYPE:
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEAttention.forward(hidden_states, attention_mask=None, position_ids=None, past_key_value=None, output_attentions=False, use_cache=False, **kwargs)
¶
Constructs the JetMoEAttention.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
TYPE:
|
hidden_states |
The input hidden states with shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask tensor with shape (batch_size, 1, sequence_length, key_value_sequence_length). Defaults to None.
TYPE:
|
position_ids |
The position ids tensor with shape (batch_size, sequence_length). Defaults to None.
TYPE:
|
past_key_value |
The past key-value cache. Defaults to None.
TYPE:
|
output_attentions |
Whether to return the attention weights. Defaults to False.
TYPE:
|
use_cache |
Whether to use cache for the key-value pairs. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Tensor, Optional[Tensor], Optional[Tuple[Tensor]]]
|
Tuple[mindspore.Tensor, Optional[mindspore.Tensor], Optional[Tuple[mindspore.Tensor]]]: A tuple containing the attention output tensor with shape (batch_size, sequence_length, hidden_size), the attention weights tensor (if output_attentions is True), and the updated past key-value cache. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the attention weights or mask have invalid shapes. |
ValueError
|
If the cache structure has changed and the layer index is not initialized for auto-regressive decoding. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEBaseModelOutputWithPast
dataclass
¶
Bases: BaseModelOutputWithPast
Base class for model's outputs that may also contain a past key/values (to speed up sequential decoding).
PARAMETER | DESCRIPTION |
---|---|
last_hidden_state |
Sequence of hidden-states at the output of the last layer of the model. If
TYPE:
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEBlock
¶
Bases: Module
The 'JetMoEBlock' class represents a module that implements a JetMoE block for a neural network model. This block consists of components such as self-attention mechanism, layer normalization, and a multi-layer perceptron (MLP) with Mixture of Experts (MoE) architecture. The block is designed to be used within a larger neural network model for various natural language processing tasks.
The class provides methods for initialization and forward pass computation. During initialization, it sets up the necessary components including input layer normalization, self-attention mechanism, post-attention layer normalization, and the MLP with MoE architecture based on the provided configuration.
The 'forward' method performs the forward pass computation of the JetMoEBlock module. It takes input hidden states, optional position IDs, past key-value states, attention mask, and other optional arguments. The method computes the self-attention output, updates the hidden states, applies the MLP operation, and returns the final outputs. Optional outputs such as attention weights and cached states can also be returned based on the method arguments.
Overall, the 'JetMoEBlock' class encapsulates the functionality of a JetMoE block within a neural network model, providing the necessary components for attention-based computations and expert-based transformations.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEBlock.__init__(config, layer_idx=None)
¶
Initialize the JetMoEBlock module.
PARAMETER | DESCRIPTION |
---|---|
config |
Configuration object with model hyperparameters.
TYPE:
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEBlock.forward(hidden_states, position_ids=None, past_key_value=None, attention_mask=None, output_attentions=False, use_cache=False, **kwargs)
¶
Forward pass of the JetMoEBlock module.
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
Input hidden states.
TYPE:
|
layer_past |
Past layer state.
TYPE:
|
attention_mask |
Attention mask.
TYPE:
|
head_mask |
Head mask.
TYPE:
|
use_cache |
Whether to use cached states.
TYPE:
|
output_attentions |
Whether to output attention weights.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple[Tensor], Optional[Tuple[Tensor, Tuple[Tensor, ...]]]]
|
Union[Tuple[mindspore.Tensor], Optional[Tuple[mindspore.Tensor, Tuple[mindspore.Tensor, ...]]]]: Tuple containing outputs or optional attention weights. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoECausalLMOutputWithPast
dataclass
¶
Bases: CausalLMOutputWithPast
Base class for causal language model (or autoregressive) outputs.
PARAMETER | DESCRIPTION |
---|---|
loss |
Language modeling loss (for next-token prediction).
TYPE:
|
logits |
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
TYPE:
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM
¶
Bases: JetMoEPreTrainedModel
The JetMoEForCausalLM class represents a JetMoE model for causal language modeling. It inherits from the JetMoEPreTrainedModel.
This class includes methods for initializing the model, getting and setting input and output embeddings, setting and getting the decoder, forwarding the model, preparing inputs for generation, and reordering cache. The forward method handles the generation of outputs based on input and model configuration, while the prepare_inputs_for_generation method prepares inputs for the generation process. Additionally, the _reorder_cache method is a static method for reordering past key values based on beam index.
The class also includes attributes for model configuration, vocabulary size, auxiliary loss coefficient, LM head, and tie_word_embeddings.
The class provides flexibility for customizing and utilizing the JetMoE model for causal language modeling tasks.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM.__init__(config)
¶
Initializes an instance of JetMoEForCausalLM.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the JetMoEForCausalLM class.
|
config |
An object containing configuration parameters for the model.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM.forward(input_ids=None, attention_mask=None, position_ids=None, past_key_values=None, inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the masked language modeling loss. Indices should either be in
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, CausalLMOutputWithPast]
|
Union[Tuple, CausalLMOutputWithPast] |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM.get_decoder()
¶
Method to retrieve the decoder model for the JetMoEForCausalLM class.
PARAMETER | DESCRIPTION |
---|---|
self |
JetMoEForCausalLM instance. The instance of the JetMoEForCausalLM class.
|
RETURNS | DESCRIPTION |
---|---|
None
|
The decoder model associated with the JetMoEForCausalLM instance. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM.get_input_embeddings()
¶
Method to retrieve the input embeddings from the model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the JetMoEForCausalLM class.
|
RETURNS | DESCRIPTION |
---|---|
embed_tokens
|
The input embeddings from the model.
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM.get_output_embeddings()
¶
Returns the output embeddings of the JetMoE model for causal language modeling.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the JetMoEForCausalLM class.
|
RETURNS | DESCRIPTION |
---|---|
The output embeddings of the JetMoE model for causal language modeling. |
Note
This method is a part of the JetMoEForCausalLM class and can be used to retrieve the output embeddings of the model. The output embeddings represent the contextualized representations of the input tokens generated by the model.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM.prepare_inputs_for_generation(input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs)
¶
Prepare inputs for generation.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the JetMoEForCausalLM class.
TYPE:
|
input_ids |
The input tensor with token IDs.
TYPE:
|
past_key_values |
The past key values for caching.
TYPE:
|
attention_mask |
The attention mask tensor to mask certain tokens.
TYPE:
|
inputs_embeds |
The embeddings tensor for input tokens.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
model_inputs
|
A dictionary containing model inputs for generation. It includes 'inputs_embeds' if inputs_embeds is provided, otherwise 'input_ids'. Additionally, 'position_ids', 'past_key_values', 'use_cache', and 'attention_mask' are included.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If past_key_values is not of type Cache or Tuple. |
IndexError
|
If attention_mask shape is inconsistent with input_ids shape. |
ValueError
|
If cache_length + input_ids length exceeds max_cache_length. |
AttributeError
|
If position_ids calculation encounters errors. |
RuntimeError
|
If there are issues with masked_fill operation. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM.set_decoder(decoder)
¶
Sets the decoder for the JetMoEForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the JetMoEForCausalLM class.
TYPE:
|
decoder |
The decoder to be set for the model.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM.set_input_embeddings(value)
¶
This method sets the input embeddings for the JetMoEForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the JetMoEForCausalLM class.
TYPE:
|
value |
The input embeddings to be set for the model. It should be a tensor of shape (vocab_size, embedding_dim).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForCausalLM.set_output_embeddings(new_embeddings)
¶
Set the output embeddings for the JetMoEForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the JetMoEForCausalLM model.
TYPE:
|
new_embeddings |
The new output embeddings to be set for the model. Should be a tensor of shape (vocab_size, hidden_size).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the new_embeddings parameter is not a valid tensor. |
ValueError
|
If the new_embeddings tensor shape does not match the expected (vocab_size, hidden_size) shape. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForSequenceClassification
¶
Bases: JetMoEPreTrainedModel
JetMoEForSequenceClassification is a class that represents a sequence classification model based on the JetMoE architecture. It is designed to handle tasks such as sentiment analysis, text classification, and natural language inference.
This class inherits from the JetMoEPreTrainedModel class, which provides a set of pre-trained parameters and methods for fine-tuning the model on specific downstream tasks.
The JetMoEForSequenceClassification class provides the following methods:
- init: Initializes the JetMoEForSequenceClassification instance with the given configuration.
- get_input_embeddings: Returns the input embeddings used by the model.
- set_input_embeddings: Sets the input embeddings of the model to the given value.
- forward: Constructs the sequence classification model and computes the output logits. It takes several optional arguments such as input_ids, attention_mask, and labels, and returns a tuple containing the loss, logits, and other outputs.
The JetMoEForSequenceClassification class follows the configuration provided to initialize the model, including the number of labels for the classification task. It utilizes the JetMoEModel for the main transformer architecture and applies a score layer to compute the logits. The forward method handles the computation of the model's output based on the given inputs and labels, including handling different problem types (regression, single-label classification, or multi-label classification) and computing the loss.
Note
This docstring does not include the method signatures or any other code for clarity and readability.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForSequenceClassification.__init__(config)
¶
Initializes a JetMoEForSequenceClassification instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance itself.
|
config |
An object containing configuration settings for the model. It should include the following attributes:
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
NotImplementedError
|
If the method 'post_init()' is not implemented. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForSequenceClassification.forward(input_ids=None, attention_mask=None, position_ids=None, past_key_values=None, inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the sequence classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForSequenceClassification.get_input_embeddings()
¶
This method retrieves the input embeddings from the JetMoEForSequenceClassification model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the JetMoEForSequenceClassification class.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns the input embeddings which are of type 'None'. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEForSequenceClassification.set_input_embeddings(value)
¶
Sets the input embeddings for the JetMoEForSequenceClassification model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the JetMoEForSequenceClassification class. |
value |
The input embeddings to be set for the model. This should be an object that provides the embedding functionality.
|
RETURNS | DESCRIPTION |
---|---|
None. |
This method allows you to set the input embeddings for the JetMoEForSequenceClassification model. The input embeddings should be provided as an object that provides the embedding functionality. By setting the input embeddings, you can customize the way the model represents the input data.
Note
The 'embed_tokens' attribute of the 'model' instance is updated with the provided 'value' to set the input embeddings.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEModel
¶
Bases: JetMoEPreTrainedModel
Transformer decoder consisting of config.num_hidden_layers layers. Each layer is a [JetMoEBlock
]
PARAMETER | DESCRIPTION |
---|---|
config |
JetMoEConfig
TYPE:
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEModel.__init__(config)
¶
Initializes a new instance of the JetMoEModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
config |
The configuration object that contains various settings for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEModel.forward(input_ids=None, attention_mask=None, position_ids=None, past_key_values=None, inputs_embeds=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
This method forwards the JetMoEModel by processing input data and generating the model output.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the JetMoEModel class.
|
input_ids |
The input tensor containing token IDs. Default is None.
TYPE:
|
attention_mask |
Optional tensor representing the attention mask. Default is None.
TYPE:
|
position_ids |
Optional tensor containing position IDs. Default is None.
TYPE:
|
past_key_values |
Optional list of tensors representing past key values. Default is None.
TYPE:
|
inputs_embeds |
Optional tensor containing input embeddings. Default is None.
TYPE:
|
use_cache |
Optional flag indicating whether to use cache. Default is None.
TYPE:
|
output_attentions |
Optional flag indicating whether to output attentions Default is None.
TYPE:
|
output_hidden_states |
Optional flag indicating whether to output hidden states. Default is None.
TYPE:
|
return_dict |
Optional flag indicating whether to return a dictionary. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithPast]
|
Union[Tuple, BaseModelOutputWithPast]: The return value is a tuple or an instance of BaseModelOutputWithPast, which contains the model output. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
Raised if both input_ids and inputs_embeds are specified, or if neither is specified, or if incompatible combinations are provided. |
Warning
|
Raised if |
ValueError
|
Raised if attempting to perform batched generation with certain settings that may lead to unexpected behavior. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEModel.get_input_embeddings()
¶
Method to retrieve the input embeddings from the JetMoEModel.
PARAMETER | DESCRIPTION |
---|---|
self |
JetMoEModel The instance of the JetMoEModel class.
|
RETURNS | DESCRIPTION |
---|---|
None Returns the input embeddings represented by embed_tokens. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEModel.set_input_embeddings(value)
¶
Set the input embeddings for the JetMoEModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the JetMoEModel class.
TYPE:
|
value |
The input embeddings to be set for the model. Should be a tensor or an object that can be assigned to self.embed_tokens.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoEPreTrainedModel.__init__(*inputs, **kwargs)
¶
Initialize the JetMoEPreTrainedModel.
PARAMETER | DESCRIPTION |
---|---|
*inputs |
Variable length input arguments.
DEFAULT:
|
**kwargs |
Keyword arguments.
DEFAULT:
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
696 697 698 699 700 701 702 703 704 705 706 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoERMSNorm
¶
Bases: Module
The 'JetMoERMSNorm' class is a custom implementation of the root mean square normalization (RMSNorm) module, specifically designed for the JetMoE model. It inherits from the 'nn.Module' class, which is a base class for all neural network modules in MindSpore.
This class provides a trainable normalization layer that performs RMS normalization on the input hidden states. The normalization is applied along the last dimension of the input tensor, reducing the variance across that dimension.
The forwardor 'init' initializes the 'JetMoERMSNorm' module. It takes two parameters: 'hidden_size' specifies the size of the hidden states, and 'eps' (default value 1e-06) is the epsilon value used for numerical stability in the normalization calculation.
The 'forward' method is the main functionality of the 'JetMoERMSNorm' module. It performs the RMS normalization on the input 'hidden_states' tensor. The method first converts the input tensor to 'mindspore.float32' to ensure consistent data type for the calculations. It then computes the variance along the last dimension of the tensor using the 'pow' and 'mean' operations. Afterward, the input tensor is multiplied element-wise by the reciprocal square root of the variance plus epsilon, using the 'rsqrt' and 'ops' operations. Finally, the normalized tensor is multiplied element-wise by the weight tensor and converted back to the original input data type.
Note that the 'JetMoERMSNorm' module is intended to be used as a part of the JetMoE model and can be applied to the hidden states of the model's components.
Please refer to the MindSpore documentation for more information on the 'nn.Module' class and the 'mindspore.float32' data type.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoERMSNorm.__init__(hidden_size, eps=1e-06)
¶
JetMoERMSNorm module
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
228 229 230 231 232 233 234 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoERMSNorm.forward(hidden_states)
¶
Constructs the JetMoERMSNorm.
This method takes in a tensor of hidden states and performs normalization using the RMSNorm technique. The normalized tensor is then multiplied by a weight parameter.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the JetMoERMSNorm class.
TYPE:
|
hidden_states |
A tensor containing the hidden states. The dtype of the tensor should be compatible with the operations performed within the method.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value. The normalization is performed in-place on the hidden_states tensor. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoERotaryEmbedding
¶
Bases: Module
The JetMoERotaryEmbedding class represents a rotary position embedding module that can be used in neural network models. It inherits from the nn.Module class and provides functionality for generating rotary position embeddings based on the input sequence length.
ATTRIBUTE | DESCRIPTION |
---|---|
dim |
The dimension of the position embeddings.
TYPE:
|
max_position_embeddings |
The maximum position embeddings allowed.
TYPE:
|
base |
The base value used in the calculation of position embeddings.
TYPE:
|
inv_freq |
The inverse frequency values used in the calculation of position embeddings.
TYPE:
|
max_seq_len_cached |
The maximum sequence length for which cosine and sine embeddings are cached.
TYPE:
|
cos_cached |
Cached cosine embeddings for the given sequence length.
TYPE:
|
sin_cached |
Cached sine embeddings for the given sequence length.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
_set_cos_sin_cache |
Sets the cosine and sine embeddings cache for a given sequence length and data type. |
forward |
Constructs the cosine and sine embeddings for the input sequence, updating the cache if necessary. |
Note
This class is designed to be used as part of neural network models, particularly in scenarios where rotary position embeddings are required.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoERotaryEmbedding.__init__(dim, max_position_embeddings=2048, base=10000)
¶
Initializes the JetMoERotaryEmbedding object with the specified parameters.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
dim |
The dimensionality of the embeddings.
TYPE:
|
max_position_embeddings |
The maximum number of position embeddings. Defaults to 2048.
TYPE:
|
base |
The base value used in the calculation. Defaults to 10000.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the dimensionality 'dim' is not a positive integer. |
ValueError
|
If 'max_position_embeddings' is not a positive integer. |
ValueError
|
If 'base' is not a positive integer. |
TypeError
|
If the data type of 'dim', 'max_position_embeddings', or 'base' is not an integer. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoERotaryEmbedding.forward(x, seq_len=None)
¶
Construct the JetMoERotaryEmbedding.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the JetMoERotaryEmbedding class.
TYPE:
|
x |
The input tensor.
It is expected to be a tensor.
|
seq_len |
The length of the sequence for which the cached values need to be forwarded.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If seq_len is not a positive integer. |
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.JetMoESequenceClassifierOutputWithPast
dataclass
¶
Bases: SequenceClassifierOutputWithPast
Base class for outputs of sentence classification models.
PARAMETER | DESCRIPTION |
---|---|
loss |
Classification (or regression if config.num_labels==1) loss.
TYPE:
|
logits |
Classification (or regression if config.num_labels==1) scores (before SoftMax).
TYPE:
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=2)
¶
Applies Rotary Position Embedding to the query and key tensors.
PARAMETER | DESCRIPTION |
---|---|
q |
The query tensor.
TYPE:
|
k |
The key tensor.
TYPE:
|
cos |
The cosine part of the rotary embedding.
TYPE:
|
sin |
The sine part of the rotary embedding.
TYPE:
|
position_ids |
The position indices of the tokens corresponding to the query and key tensors. For example, this can be used to pass offsetted position ids when working with a KV-cache.
TYPE:
|
unsqueeze_dim |
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
|
mindnlp.transformers.models.jetmoe.modeling_jetmoe.rotate_half(x)
¶
Rotates half the hidden dims of the input.
Source code in mindnlp/transformers/models/jetmoe/modeling_jetmoe.py
382 383 384 385 386 387 |
|