| 470 | } |
| 471 | |
| 472 | static VARIABLE_TYPE classify_variable(const std::string& name) { |
| 473 | std::regex pattern_self_attn("/self_attention/linear_(\\d+)/(\\w+)"); |
| 474 | std::regex pattern_attn("/attention/linear_(\\d+)/(\\w+)"); |
| 475 | std::regex pattern_ffn("/ffn/linear_(\\d+)(\\w*)/(\\w+)"); |
| 476 | |
| 477 | std::smatch match; |
| 478 | |
| 479 | if (std::regex_search(name, match, pattern_self_attn)) { |
| 480 | int layer_number = std::stoi(match[1]); |
| 481 | std::string parameterName = match[2]; |
| 482 | |
| 483 | switch (layer_number) { |
| 484 | case 0: |
| 485 | if (parameterName == "bias") |
| 486 | return VARIABLE_TYPE::SELF_ATTN_LINEAR_0_BIAS; |
| 487 | if (parameterName == "weight") |
| 488 | return VARIABLE_TYPE::SELF_ATTN_LINEAR_0_WEIGHT; |
| 489 | else |
| 490 | return VARIABLE_TYPE::SELF_ATTN_LINEAR_0_WEIGHT_SCALE; |
| 491 | case 1: |
| 492 | if (parameterName == "weight") |
| 493 | return VARIABLE_TYPE::SELF_ATTN_LINEAR_1_WEIGHT; |
| 494 | default: |
| 495 | return VARIABLE_TYPE::OTHERS; |
| 496 | }; |
| 497 | } |
| 498 | else if (std::regex_search(name, match, pattern_attn)) { |
| 499 | int layer_number = std::stoi(match[1]); |
| 500 | std::string parameterName = match[2]; |
| 501 | |
| 502 | switch (layer_number) { |
| 503 | case 0: |
| 504 | if (parameterName == "bias") |
| 505 | return VARIABLE_TYPE::ATTN_LINEAR_0_BIAS; |
| 506 | if (parameterName == "weight") |
| 507 | return VARIABLE_TYPE::ATTN_LINEAR_0_WEIGHT; |
| 508 | return VARIABLE_TYPE::ATTN_LINEAR_0_WEIGHT_SCALE; |
| 509 | case 1: |
| 510 | if (parameterName == "bias") |
| 511 | return VARIABLE_TYPE::ATTN_LINEAR_1_BIAS; |
| 512 | if (parameterName == "weight") |
| 513 | return VARIABLE_TYPE::ATTN_LINEAR_1_WEIGHT; |
| 514 | return VARIABLE_TYPE::ATTN_LINEAR_1_WEIGHT_SCALE; |
| 515 | case 2: |
| 516 | if (parameterName == "weight") |
| 517 | return VARIABLE_TYPE::ATTN_LINEAR_2_WEIGHT; |
| 518 | default: |
| 519 | return VARIABLE_TYPE::OTHERS; |
| 520 | }; |
| 521 | } |
| 522 | else if (std::regex_search(name, match, pattern_ffn)) { |
| 523 | int layer_number = std::stoi(match[1]); |
| 524 | std::string noact = match[2]; |
| 525 | std::string parameterName = match[3]; |
| 526 | |
| 527 | switch (layer_number) { |
| 528 | case 0: |
| 529 | if (noact == "noact" && parameterName == "bias") |