rwkv
mindnlp.transformers.models.rwkv.modeling_rwkv
¶
MindSpore RWKV model.
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvBlock
¶
Bases: Module
RWKV block
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
418 419 420 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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvBlock.__init__(config, layer_id)
¶
Initialize the RwkvBlock.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvBlock class.
|
config |
An object containing configuration settings for the block.
|
layer_id |
An integer representing the layer id.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If layer_id is a negative integer. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
420 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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvBlock.forward(hidden, state=None, use_cache=False, output_attentions=False)
¶
Method to forward a RwkvBlock.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvBlock class.
|
hidden |
The input hidden tensor to be processed.
TYPE:
|
state |
The current state tensor. Defaults to None.
TYPE:
|
use_cache |
Flag indicating whether to use cache. Defaults to False.
TYPE:
|
output_attentions |
Flag indicating whether to output attentions.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple
|
A tuple containing the processed hidden tensor and the updated state tensor. If output_attentions is True, the tuple also includes the attention tensor; otherwise, it includes None. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvCausalLMOutput
dataclass
¶
Bases: ModelOutput
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:
|
state |
The state of the model at the last time step. Can be used in a forward method with the next
TYPE:
|
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvFeedForward
¶
Bases: Module
RWKV feed forward
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 379 380 381 382 383 384 385 386 387 388 389 390 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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvFeedForward.__init__(config, layer_id=0)
¶
Initializes a new instance of the RwkvFeedForward class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvFeedForward class.
|
config |
The configuration for the feedforward layer, containing the hidden size and intermediate size parameters.
|
layer_id |
The ID of the layer.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvFeedForward.forward(hidden, state=None)
¶
This method 'forward' is defined in the class 'RwkvFeedForward' and is responsible for forwarding the value and state based on the input parameters.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvFeedForward class.
|
hidden |
The input array representing the hidden state. It is used to calculate the key, value, and receptance. The array should have the shape (batch_size, sequence_length, feature_dim).
TYPE:
|
state |
The optional input array representing the state. It is used for calculating the shifted value. If provided, it should have the same shape as 'hidden' (batch_size, sequence_length, feature_dim). Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
A tuple containing the calculated receptance and the updated state. The receptance is a weighted value based on the key and shifted values. The updated state represents the modified state based on the input hidden array. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the shape of the 'hidden' array is not compatible for the calculations required in the method. |
IndexError
|
If the 'state' is provided and its shape does not match with the 'hidden' array. |
TypeError
|
If the input parameters are not of the expected type. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvForCausalLM
¶
Bases: RwkvPreTrainedModel
RWKV for causal LM
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvForCausalLM.__init__(config)
¶
Initializes an instance of the RwkvForCausalLM class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvForCausalLM class.
TYPE:
|
config |
The configuration object containing various settings for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvForCausalLM.forward(input_ids=None, attention_mask=None, inputs_embeds=None, state=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for language modeling. Note that the labels are shifted inside the model, i.e. you can set
TYPE:
|
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvForCausalLM.get_output_embeddings()
¶
get output embeddings
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
850 851 852 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvForCausalLM.prepare_inputs_for_generation(input_ids, state=None, inputs_embeds=None, **kwargs)
¶
prepare inputs
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
858 859 860 861 862 863 864 865 866 867 868 869 870 871 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvForCausalLM.set_output_embeddings(new_embeddings)
¶
set output embeddings
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
854 855 856 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvLinearAttention
¶
Bases: Module
RWKV linear attention
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 172 173 174 175 176 177 178 179 180 181 182 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvLinearAttention.__init__(config)
¶
Initializes an instance of the RwkvLinearAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvLinearAttention class.
TYPE:
|
config |
The configuration object containing the context length parameter. It is used to set the maximum sequence length and load CUDA kernels. Must have the attribute 'context_length' specifying the context length.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the 'config' object does not have the 'context_length' attribute. |
RuntimeError
|
If there is an issue loading the CUDA kernels. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvLinearAttention.bprop(w, u, k, v, s, return_state, y, gy)
¶
bporp for wkv
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
172 173 174 175 176 177 178 179 180 181 182 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvLinearAttention.forward(time_decay, time_first, key, value, state=None, return_state=False)
¶
Constructs the linear attention mechanism for the RwkvLinearAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvLinearAttention class.
|
time_decay |
The time decay factor for the attention mechanism.
TYPE:
|
time_first |
The time first factor for the attention mechanism.
TYPE:
|
key |
The input tensor representing the keys for the attention mechanism. The shape of the tensor should be (batch_size, seq_len, hidden_size).
TYPE:
|
value |
The input tensor representing the values for the attention mechanism. The shape of the tensor should be (batch_size, seq_len, hidden_size).
TYPE:
|
state |
The optional input tensor representing the state for the attention mechanism. It has a default value of None. The shape of the tensor should be (batch_size, hidden_size, 3).
TYPE:
|
return_state |
A flag indicating whether to return the state. It has a default value of False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Tensor, Tensor]: A tuple containing the output tensor of the attention mechanism |
|
and the state tensor if return_state is True. The output tensor represents the result of |
|
the attention mechanism. |
|
The state tensor represents the updated state of the attention mechanism if return_state is True. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the sequence length is greater than the maximum sequence length allowed by the model. |
ValueError
|
If the product of batch size and hidden size is not a round multiple of the minimum of the hidden size and 32. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvModel
¶
Bases: RwkvPreTrainedModel
RWKV Model
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 682 683 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 725 726 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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvModel.__init__(config)
¶
Initializes an instance of the RwkvModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing the configuration parameters for the model.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvModel.forward(input_ids=None, attention_mask=None, inputs_embeds=None, state=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
This method forwards the RwkvModel based on the provided input and configuration parameters.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvModel class.
|
input_ids |
The input tensor containing token indices. Default is None.
TYPE:
|
attention_mask |
The attention mask tensor to mask out specific tokens. Default is None.
TYPE:
|
inputs_embeds |
The input embeddings tensor. Default is None.
TYPE:
|
state |
The list of state tensors for caching. Default is None.
TYPE:
|
use_cache |
Flag indicating whether to use caching. Default is None.
TYPE:
|
output_attentions |
Flag indicating whether to output attentions. Default is None.
TYPE:
|
output_hidden_states |
Flag indicating whether to output hidden states. Default is None.
TYPE:
|
return_dict |
Flag indicating whether to return a dictionary. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, RwkvOutput]
|
Union[Tuple, RwkvOutput]: The output of the method, which can be a tuple of hidden states, states, hidden states history, and attentions, or an instance of RwkvOutput. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If both input_ids and inputs_embeds are specified at the same time, or if neither input_ids nor inputs_embeds are specified. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 725 726 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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvModel.get_input_embeddings()
¶
This method returns the input embeddings used in the RwkvModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvModel class.
|
RETURNS | DESCRIPTION |
---|---|
embeddings
|
This method returns the input embeddings associated with the RwkvModel instance. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvModel.set_input_embeddings(new_embeddings)
¶
Sets the input embeddings for the RwkvModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the RwkvModel class.
TYPE:
|
new_embeddings |
A new set of input embeddings to be assigned to the RwkvModel. This should be of the same type and shape as the current embeddings. The input embeddings are used as the initial embeddings for the model.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvOutput
dataclass
¶
Bases: ModelOutput
Class for the RWKV model outputs.
PARAMETER | DESCRIPTION |
---|---|
last_hidden_state |
Sequence of hidden-states at the output of the last layer of the model.
TYPE:
|
state |
The state of the model at the last time step. Can be used in a forward method with the next
TYPE:
|
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 581 582 583 584 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvPreTrainedModel
¶
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/rwkv/modeling_rwkv.py
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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvSelfAttention
¶
Bases: Module
RWKV self attention
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 260 261 262 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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvSelfAttention.__init__(config, layer_id=0)
¶
Initializes an instance of the RwkvSelfAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
The configuration object containing various settings.
TYPE:
|
layer_id |
The ID of the layer. Defaults to 0.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvSelfAttention.extract_key_value(hidden, state=None)
¶
extrac key value
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.RwkvSelfAttention.forward(hidden, state=None, use_cache=False)
¶
Construct method in the RwkvSelfAttention class.
This method forwards the self-attention mechanism for the Rwkv model. It takes in the hidden input, the state, and a flag indicating whether to use cache or not. It returns the output of the attention mechanism and the updated state.
PARAMETER | DESCRIPTION |
---|---|
self |
The RwkvSelfAttention object.
|
hidden |
A tensor containing the hidden input.
|
state |
A tensor containing the current state (default: None).
DEFAULT:
|
use_cache |
A boolean flag indicating whether to use cache (default: False).
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
A tuple containing the output of the attention mechanism and the updated state. |
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
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 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.load_wkv_cuda_kernel(func_name, context_length)
¶
load wkv cuda kernel
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
mindnlp.transformers.models.rwkv.modeling_rwkv.rwkv_linear_attention_cpu(time_decay, time_first, key, value, state=None, return_state=False)
¶
CPU WKV implementation.
Source code in mindnlp/transformers/models/rwkv/modeling_rwkv.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 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 |
|
mindnlp.transformers.models.rwkv.configuration_rwkv
¶
RWKV configuration
mindnlp.transformers.models.rwkv.configuration_rwkv.RwkvConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [RwkvModel
]. It is used to instantiate a RWKV
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the RWVK-4
RWKV/rwkv-4-169m-pile architecture.
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 RWKV model. Defines the number of different tokens that can be represented by the
TYPE:
|
context_length |
The maximum sequence length that this model can be be used with in a single forward (using it in RNN mode lets use any sequence length).
TYPE:
|
hidden_size |
Dimensionality of the embeddings and hidden states.
TYPE:
|
num_hidden_layers |
Number of hidden layers in the model.
TYPE:
|
attention_hidden_size |
Dimensionality of the attention hidden states. Will default to
TYPE:
|
intermediate_size |
Dimensionality of the inner feed-forward layers. Will default to 4 times
TYPE:
|
layer_norm_eps |
The epsilon to use in the layer normalization layers.
TYPE:
|
bos_token_id |
The id of the beginning of sentence token in the vocabulary. Defaults to 0 as RWKV uses the same tokenizer as GPTNeoX.
TYPE:
|
eos_token_id |
The id of the end of sentence token in the vocabulary. Defaults to 0 as RWKV uses the same tokenizer as GPTNeoX.
TYPE:
|
rescale_every |
At inference, the hidden states (and weights of the correponding output layers) are divided by 2 every
TYPE:
|
tie_word_embeddings |
Whether or not to tie the word embeddings with the input token embeddings.
TYPE:
|
use_cache |
Whether or not the model should return the last state.
TYPE:
|
Example
>>> from transformers import RwkvConfig, RwkvModel
...
>>> # Initializing a Rwkv configuration
>>> configuration = RwkvConfig()
...
>>> # Initializing a model (with random weights) from the configuration
>>> model = RwkvModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/rwkv/configuration_rwkv.py
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 |
|
mindnlp.transformers.models.rwkv.configuration_rwkv.RwkvConfig.__init__(vocab_size=50277, context_length=1024, hidden_size=4096, num_hidden_layers=32, attention_hidden_size=None, intermediate_size=None, layer_norm_epsilon=1e-05, bos_token_id=0, eos_token_id=0, rescale_every=6, tie_word_embeddings=False, use_cache=True, **kwargs)
¶
Initializes an instance of RwkvConfig.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance itself.
|
vocab_size |
The size of the vocabulary. Default is 50277.
TYPE:
|
context_length |
The length of the context. Default is 1024.
TYPE:
|
hidden_size |
The size of the hidden layers. Default is 4096.
TYPE:
|
num_hidden_layers |
The number of hidden layers. Default is 32.
TYPE:
|
attention_hidden_size |
The size of the attention hidden layer. Defaults to hidden_size if not provided.
TYPE:
|
intermediate_size |
The size of the intermediate layer. Defaults to 4 times hidden_size if not provided.
TYPE:
|
layer_norm_epsilon |
The epsilon value for layer normalization. Default is 1e-05.
TYPE:
|
bos_token_id |
The beginning of sentence token id. Default is 0.
TYPE:
|
eos_token_id |
The end of sentence token id. Default is 0.
TYPE:
|
rescale_every |
The frequency of rescaling. Default is 6.
TYPE:
|
tie_word_embeddings |
Whether to tie word embeddings. Default is False.
TYPE:
|
use_cache |
Whether to use cache. Default is True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the provided vocab_size, context_length, hidden_size, num_hidden_layers, attention_hidden_size, intermediate_size, layer_norm_epsilon, bos_token_id, eos_token_id, or rescale_every is not a positive integer. |
TypeError
|
If any of the provided parameters has an unexpected type. |
Source code in mindnlp/transformers/models/rwkv/configuration_rwkv.py
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 |
|