Upload checkpoint-1550
Browse files- added_tokens.json +30 -0
- chat_template.jinja +85 -0
- config.json +45 -0
- configuration_sdar.py +212 -0
- dynamic_blocks_utils.py +223 -0
- fused_linear_diffusion_cross_entropy.py +723 -0
- generation_config.json +13 -0
- latest +1 -0
- merges.txt +0 -0
- model-00001-of-00002.safetensors +3 -0
- model-00002-of-00002.safetensors +3 -0
- model.safetensors.index.json +406 -0
- modeling_sdar.py +1245 -0
- rng_state_0.pth +3 -0
- rng_state_1.pth +3 -0
- rng_state_2.pth +3 -0
- rng_state_3.pth +3 -0
- rng_state_4.pth +3 -0
- rng_state_5.pth +3 -0
- rng_state_6.pth +3 -0
- scheduler.pt +3 -0
- special_tokens_map.json +40 -0
- tokenization_qwen2.py +342 -0
- tokenizer_config.json +265 -0
- trainer_state.json +2204 -0
- training_args.bin +3 -0
- vocab.json +0 -0
- zero_to_fp32.py +760 -0
added_tokens.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"</think>": 151668,
|
| 3 |
+
"</tool_call>": 151658,
|
| 4 |
+
"</tool_response>": 151666,
|
| 5 |
+
"<EOB>": 151670,
|
| 6 |
+
"<think>": 151667,
|
| 7 |
+
"<tool_call>": 151657,
|
| 8 |
+
"<tool_response>": 151665,
|
| 9 |
+
"<|MASK|>": 151669,
|
| 10 |
+
"<|box_end|>": 151649,
|
| 11 |
+
"<|box_start|>": 151648,
|
| 12 |
+
"<|endoftext|>": 151643,
|
| 13 |
+
"<|file_sep|>": 151664,
|
| 14 |
+
"<|fim_middle|>": 151660,
|
| 15 |
+
"<|fim_pad|>": 151662,
|
| 16 |
+
"<|fim_prefix|>": 151659,
|
| 17 |
+
"<|fim_suffix|>": 151661,
|
| 18 |
+
"<|im_end|>": 151645,
|
| 19 |
+
"<|im_start|>": 151644,
|
| 20 |
+
"<|image_pad|>": 151655,
|
| 21 |
+
"<|object_ref_end|>": 151647,
|
| 22 |
+
"<|object_ref_start|>": 151646,
|
| 23 |
+
"<|quad_end|>": 151651,
|
| 24 |
+
"<|quad_start|>": 151650,
|
| 25 |
+
"<|repo_name|>": 151663,
|
| 26 |
+
"<|video_pad|>": 151656,
|
| 27 |
+
"<|vision_end|>": 151653,
|
| 28 |
+
"<|vision_pad|>": 151654,
|
| 29 |
+
"<|vision_start|>": 151652
|
| 30 |
+
}
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if tools %}
|
| 2 |
+
{{- '<|im_start|>system\n' }}
|
| 3 |
+
{%- if messages[0].role == 'system' %}
|
| 4 |
+
{{- messages[0].content + '\n\n' }}
|
| 5 |
+
{%- endif %}
|
| 6 |
+
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
| 7 |
+
{%- for tool in tools %}
|
| 8 |
+
{{- "\n" }}
|
| 9 |
+
{{- tool | tojson }}
|
| 10 |
+
{%- endfor %}
|
| 11 |
+
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
| 12 |
+
{%- else %}
|
| 13 |
+
{%- if messages[0].role == 'system' %}
|
| 14 |
+
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
|
| 15 |
+
{%- endif %}
|
| 16 |
+
{%- endif %}
|
| 17 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 18 |
+
{%- for message in messages[::-1] %}
|
| 19 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 20 |
+
{%- if ns.multi_step_tool and message.role == "user" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
|
| 21 |
+
{%- set ns.multi_step_tool = false %}
|
| 22 |
+
{%- set ns.last_query_index = index %}
|
| 23 |
+
{%- endif %}
|
| 24 |
+
{%- endfor %}
|
| 25 |
+
{%- for message in messages %}
|
| 26 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 27 |
+
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
|
| 28 |
+
{%- elif message.role == "assistant" %}
|
| 29 |
+
{%- set content = message.content %}
|
| 30 |
+
{%- set reasoning_content = '' %}
|
| 31 |
+
{%- if message.reasoning_content is defined and message.reasoning_content is not none %}
|
| 32 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 33 |
+
{%- else %}
|
| 34 |
+
{%- if '</think>' in message.content %}
|
| 35 |
+
{%- set content = message.content.split('</think>')[-1].lstrip('\n') %}
|
| 36 |
+
{%- set reasoning_content = message.content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 37 |
+
{%- endif %}
|
| 38 |
+
{%- endif %}
|
| 39 |
+
{%- if loop.index0 > ns.last_query_index %}
|
| 40 |
+
{%- if loop.last or (not loop.last and reasoning_content) %}
|
| 41 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
|
| 42 |
+
{%- else %}
|
| 43 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 44 |
+
{%- endif %}
|
| 45 |
+
{%- else %}
|
| 46 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 47 |
+
{%- endif %}
|
| 48 |
+
{%- if message.tool_calls %}
|
| 49 |
+
{%- for tool_call in message.tool_calls %}
|
| 50 |
+
{%- if (loop.first and content) or (not loop.first) %}
|
| 51 |
+
{{- '\n' }}
|
| 52 |
+
{%- endif %}
|
| 53 |
+
{%- if tool_call.function %}
|
| 54 |
+
{%- set tool_call = tool_call.function %}
|
| 55 |
+
{%- endif %}
|
| 56 |
+
{{- '<tool_call>\n{"name": "' }}
|
| 57 |
+
{{- tool_call.name }}
|
| 58 |
+
{{- '", "arguments": ' }}
|
| 59 |
+
{%- if tool_call.arguments is string %}
|
| 60 |
+
{{- tool_call.arguments }}
|
| 61 |
+
{%- else %}
|
| 62 |
+
{{- tool_call.arguments | tojson }}
|
| 63 |
+
{%- endif %}
|
| 64 |
+
{{- '}\n</tool_call>' }}
|
| 65 |
+
{%- endfor %}
|
| 66 |
+
{%- endif %}
|
| 67 |
+
{{- '<|im_end|>\n' }}
|
| 68 |
+
{%- elif message.role == "tool" %}
|
| 69 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 70 |
+
{{- '<|im_start|>user' }}
|
| 71 |
+
{%- endif %}
|
| 72 |
+
{{- '\n<tool_response>\n' }}
|
| 73 |
+
{{- message.content }}
|
| 74 |
+
{{- '\n</tool_response>' }}
|
| 75 |
+
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 76 |
+
{{- '<|im_end|>\n' }}
|
| 77 |
+
{%- endif %}
|
| 78 |
+
{%- endif %}
|
| 79 |
+
{%- endfor %}
|
| 80 |
+
{%- if add_generation_prompt %}
|
| 81 |
+
{{- '<|im_start|>assistant\n' }}
|
| 82 |
+
{%- if enable_thinking is defined and enable_thinking is false %}
|
| 83 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 84 |
+
{%- endif %}
|
| 85 |
+
{%- endif %}
|
config.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"SDARForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"auto_map": {
|
| 8 |
+
"AutoConfig": "configuration_sdar.SDARConfig",
|
| 9 |
+
"AutoModel": "modeling_sdar.SDARForCausalLM",
|
| 10 |
+
"AutoModelForCausalLM": "modeling_sdar.SDARForCausalLM"
|
| 11 |
+
},
|
| 12 |
+
"block_size": 4,
|
| 13 |
+
"bos_token_id": 151643,
|
| 14 |
+
"debug": false,
|
| 15 |
+
"dynamic_blocks": false,
|
| 16 |
+
"eob_token_id": 151670,
|
| 17 |
+
"eos_token_id": 151643,
|
| 18 |
+
"ep_size": 1,
|
| 19 |
+
"fuse_cross_entropy": true,
|
| 20 |
+
"head_dim": 128,
|
| 21 |
+
"hidden_act": "silu",
|
| 22 |
+
"hidden_size": 2560,
|
| 23 |
+
"initializer_range": 0.02,
|
| 24 |
+
"intermediate_size": 9728,
|
| 25 |
+
"mask_token_id": 151669,
|
| 26 |
+
"max_position_embeddings": 32768,
|
| 27 |
+
"max_window_layers": 36,
|
| 28 |
+
"micro_forward": false,
|
| 29 |
+
"model_type": "sdar",
|
| 30 |
+
"num_attention_heads": 32,
|
| 31 |
+
"num_hidden_layers": 36,
|
| 32 |
+
"num_key_value_heads": 8,
|
| 33 |
+
"rms_norm_eps": 1e-06,
|
| 34 |
+
"rope_scaling": null,
|
| 35 |
+
"rope_theta": 1000000,
|
| 36 |
+
"skip_checkpoint": false,
|
| 37 |
+
"sliding_window": null,
|
| 38 |
+
"tie_word_embeddings": false,
|
| 39 |
+
"torch_dtype": "bfloat16",
|
| 40 |
+
"transformers_version": "4.52.4",
|
| 41 |
+
"use_cache": false,
|
| 42 |
+
"use_deepep": false,
|
| 43 |
+
"use_sliding_window": false,
|
| 44 |
+
"vocab_size": 151936
|
| 45 |
+
}
|
configuration_sdar.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
"""SDAR model configuration"""
|
| 16 |
+
|
| 17 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 18 |
+
from transformers.modeling_rope_utils import rope_config_validation
|
| 19 |
+
from transformers.utils import logging
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
logger = logging.get_logger(__name__)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class SDARConfig(PretrainedConfig):
|
| 26 |
+
r"""
|
| 27 |
+
This is the configuration class to store the configuration of a [`SDARModel`]. It is used to instantiate a
|
| 28 |
+
SDAR model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
| 29 |
+
with the defaults will yield a similar configuration to that of
|
| 30 |
+
SDAR-1.7B [DiffuOpen/SDAR-1.7B-Chat](https://huggingface.co/DiffuOpen/SDAR-1.7B-Chat/).
|
| 31 |
+
|
| 32 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 33 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Args:
|
| 37 |
+
vocab_size (`int`, *optional*, defaults to 151936):
|
| 38 |
+
Vocabulary size of the SDAR model. Defines the number of different tokens that can be represented by the
|
| 39 |
+
`inputs_ids` passed when calling [`SDARModel`]
|
| 40 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
| 41 |
+
Dimension of the hidden representations.
|
| 42 |
+
intermediate_size (`int`, *optional*, defaults to 22016):
|
| 43 |
+
Dimension of the MLP representations.
|
| 44 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 45 |
+
Number of hidden layers in the Transformer encoder.
|
| 46 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 47 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 48 |
+
num_key_value_heads (`int`, *optional*, defaults to 32):
|
| 49 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 50 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 51 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 52 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 53 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 54 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
|
| 55 |
+
head_dim (`int`, *optional*, defaults to 128):
|
| 56 |
+
The attention head dimension.
|
| 57 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 58 |
+
The non-linear activation function (function or string) in the decoder.
|
| 59 |
+
max_position_embeddings (`int`, *optional*, defaults to 32768):
|
| 60 |
+
The maximum sequence length that this model might ever be used with.
|
| 61 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 62 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 63 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
| 64 |
+
The epsilon used by the rms normalization layers.
|
| 65 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 66 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 67 |
+
relevant if `config.is_decoder=True`.
|
| 68 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 69 |
+
Whether the model's input and output word embeddings should be tied.
|
| 70 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 71 |
+
The base period of the RoPE embeddings.
|
| 72 |
+
rope_scaling (`Dict`, *optional*):
|
| 73 |
+
Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
|
| 74 |
+
and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
|
| 75 |
+
accordingly.
|
| 76 |
+
Expected contents:
|
| 77 |
+
`rope_type` (`str`):
|
| 78 |
+
The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
|
| 79 |
+
'llama3'], with 'default' being the original RoPE implementation.
|
| 80 |
+
`factor` (`float`, *optional*):
|
| 81 |
+
Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
|
| 82 |
+
most scaling types, a `factor` of x will enable the model to handle sequences of length x *
|
| 83 |
+
original maximum pre-trained length.
|
| 84 |
+
`original_max_position_embeddings` (`int`, *optional*):
|
| 85 |
+
Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
|
| 86 |
+
pretraining.
|
| 87 |
+
`attention_factor` (`float`, *optional*):
|
| 88 |
+
Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
|
| 89 |
+
computation. If unspecified, it defaults to value recommended by the implementation, using the
|
| 90 |
+
`factor` field to infer the suggested value.
|
| 91 |
+
`beta_fast` (`float`, *optional*):
|
| 92 |
+
Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
|
| 93 |
+
ramp function. If unspecified, it defaults to 32.
|
| 94 |
+
`beta_slow` (`float`, *optional*):
|
| 95 |
+
Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
|
| 96 |
+
ramp function. If unspecified, it defaults to 1.
|
| 97 |
+
`short_factor` (`List[float]`, *optional*):
|
| 98 |
+
Only used with 'longrope'. The scaling factor to be applied to short contexts (<
|
| 99 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
| 100 |
+
size divided by the number of attention heads divided by 2
|
| 101 |
+
`long_factor` (`List[float]`, *optional*):
|
| 102 |
+
Only used with 'longrope'. The scaling factor to be applied to long contexts (<
|
| 103 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
| 104 |
+
size divided by the number of attention heads divided by 2
|
| 105 |
+
`low_freq_factor` (`float`, *optional*):
|
| 106 |
+
Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
|
| 107 |
+
`high_freq_factor` (`float`, *optional*):
|
| 108 |
+
Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
|
| 109 |
+
attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
|
| 110 |
+
Whether to use a bias in the query, key, value and output projection layers during self-attention.
|
| 111 |
+
use_sliding_window (`bool`, *optional*, defaults to `False`):
|
| 112 |
+
Whether to use sliding window attention.
|
| 113 |
+
sliding_window (`int`, *optional*, defaults to 4096):
|
| 114 |
+
Sliding window attention (SWA) window size. If not specified, will default to `4096`.
|
| 115 |
+
max_window_layers (`int`, *optional*, defaults to 28):
|
| 116 |
+
The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
|
| 117 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 118 |
+
The dropout ratio for the attention probabilities.
|
| 119 |
+
|
| 120 |
+
```python
|
| 121 |
+
>>> from transformers import SDARModel, SDARConfig
|
| 122 |
+
|
| 123 |
+
>>> # Initializing a SDAR style configuration
|
| 124 |
+
>>> configuration = SDARConfig()
|
| 125 |
+
|
| 126 |
+
>>> # Initializing a model from the SDAR-8B style configuration
|
| 127 |
+
>>> model = SDARModel(configuration)
|
| 128 |
+
|
| 129 |
+
>>> # Accessing the model configuration
|
| 130 |
+
>>> configuration = model.config
|
| 131 |
+
```"""
|
| 132 |
+
|
| 133 |
+
model_type = "sdar"
|
| 134 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 135 |
+
|
| 136 |
+
# Default tensor parallel plan for base model `SDAR`
|
| 137 |
+
base_model_tp_plan = {
|
| 138 |
+
"layers.*.self_attn.q_proj": "colwise",
|
| 139 |
+
"layers.*.self_attn.k_proj": "colwise",
|
| 140 |
+
"layers.*.self_attn.v_proj": "colwise",
|
| 141 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
| 142 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 143 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 144 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 145 |
+
}
|
| 146 |
+
base_model_pp_plan = {
|
| 147 |
+
"embed_tokens": (["input_ids"], ["inputs_embeds"]),
|
| 148 |
+
"layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
|
| 149 |
+
"norm": (["hidden_states"], ["hidden_states"]),
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
def __init__(
|
| 153 |
+
self,
|
| 154 |
+
vocab_size=151936,
|
| 155 |
+
hidden_size=4096,
|
| 156 |
+
intermediate_size=22016,
|
| 157 |
+
num_hidden_layers=32,
|
| 158 |
+
num_attention_heads=32,
|
| 159 |
+
num_key_value_heads=32,
|
| 160 |
+
head_dim=128,
|
| 161 |
+
hidden_act="silu",
|
| 162 |
+
max_position_embeddings=32768,
|
| 163 |
+
initializer_range=0.02,
|
| 164 |
+
rms_norm_eps=1e-6,
|
| 165 |
+
use_cache=True,
|
| 166 |
+
tie_word_embeddings=False,
|
| 167 |
+
rope_theta=10000.0,
|
| 168 |
+
rope_scaling=None,
|
| 169 |
+
attention_bias=False,
|
| 170 |
+
use_sliding_window=False,
|
| 171 |
+
sliding_window=4096,
|
| 172 |
+
max_window_layers=28,
|
| 173 |
+
attention_dropout=0.0,
|
| 174 |
+
**kwargs,
|
| 175 |
+
):
|
| 176 |
+
self.vocab_size = vocab_size
|
| 177 |
+
self.max_position_embeddings = max_position_embeddings
|
| 178 |
+
self.hidden_size = hidden_size
|
| 179 |
+
self.intermediate_size = intermediate_size
|
| 180 |
+
self.num_hidden_layers = num_hidden_layers
|
| 181 |
+
self.num_attention_heads = num_attention_heads
|
| 182 |
+
self.use_sliding_window = use_sliding_window
|
| 183 |
+
self.sliding_window = sliding_window # we check `use_sliding_window` in the modeling code
|
| 184 |
+
self.max_window_layers = max_window_layers
|
| 185 |
+
|
| 186 |
+
# for backward compatibility
|
| 187 |
+
if num_key_value_heads is None:
|
| 188 |
+
num_key_value_heads = num_attention_heads
|
| 189 |
+
|
| 190 |
+
self.num_key_value_heads = num_key_value_heads
|
| 191 |
+
self.head_dim = head_dim
|
| 192 |
+
self.hidden_act = hidden_act
|
| 193 |
+
self.initializer_range = initializer_range
|
| 194 |
+
self.rms_norm_eps = rms_norm_eps
|
| 195 |
+
self.use_cache = use_cache
|
| 196 |
+
self.rope_theta = rope_theta
|
| 197 |
+
self.rope_scaling = rope_scaling
|
| 198 |
+
self.attention_bias = attention_bias
|
| 199 |
+
self.attention_dropout = attention_dropout
|
| 200 |
+
# Validate the correctness of rotary position embeddings parameters
|
| 201 |
+
# BC: if there is a 'type' field, move it to 'rope_type'.
|
| 202 |
+
if self.rope_scaling is not None and "type" in self.rope_scaling:
|
| 203 |
+
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
|
| 204 |
+
rope_config_validation(self)
|
| 205 |
+
|
| 206 |
+
super().__init__(
|
| 207 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 208 |
+
**kwargs,
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
__all__ = ["SDARConfig"]
|
dynamic_blocks_utils.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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Utility functions for dynamic block training with variable-length blocks.
|
| 3 |
+
|
| 4 |
+
This module provides functions to extract block boundaries from <EOB> tokens
|
| 5 |
+
and generate attention masks for variable-length blocks.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
from typing import List, Tuple
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def calculate_block_nums_from_eob(
|
| 13 |
+
input_ids: torch.Tensor,
|
| 14 |
+
num_tokens_list: List[List[int]],
|
| 15 |
+
eob_token_id: int
|
| 16 |
+
) -> List[List[torch.Tensor]]:
|
| 17 |
+
"""
|
| 18 |
+
Extract variable block lengths from <EOB> token positions, respecting packed sample boundaries.
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
input_ids: Token IDs tensor, shape (batch_size, seq_len)
|
| 22 |
+
num_tokens_list: List of lists, where each inner list contains sequence lengths for a batch item.
|
| 23 |
+
(Output from calculate_token_nums)
|
| 24 |
+
eob_token_id: Token ID for <EOB>
|
| 25 |
+
|
| 26 |
+
Returns:
|
| 27 |
+
List of lists of tensors. Outer list is batch. Inner list is samples.
|
| 28 |
+
Each tensor contains block lengths for that sample.
|
| 29 |
+
"""
|
| 30 |
+
batch_size, seq_len = input_ids.shape
|
| 31 |
+
all_batch_block_lengths = []
|
| 32 |
+
|
| 33 |
+
for i in range(batch_size):
|
| 34 |
+
current_ids = input_ids[i]
|
| 35 |
+
sample_lengths = num_tokens_list[i] # List of integers
|
| 36 |
+
|
| 37 |
+
current_sample_block_lengths = []
|
| 38 |
+
start_idx = 0
|
| 39 |
+
|
| 40 |
+
for length in sample_lengths:
|
| 41 |
+
# Handle tensor or int
|
| 42 |
+
if isinstance(length, torch.Tensor):
|
| 43 |
+
length = length.item()
|
| 44 |
+
|
| 45 |
+
# Extract sample tokens
|
| 46 |
+
end_idx = start_idx + length
|
| 47 |
+
# Ensure we don't go out of bounds (e.g. if sum(lengths) != seq_len due to padding logic differences)
|
| 48 |
+
# But typically sum(lengths) == seq_len for packed data + padding
|
| 49 |
+
end_idx = min(end_idx, seq_len)
|
| 50 |
+
|
| 51 |
+
if start_idx >= seq_len:
|
| 52 |
+
break
|
| 53 |
+
|
| 54 |
+
sample_ids = current_ids[start_idx:end_idx]
|
| 55 |
+
|
| 56 |
+
# Find positions of <EOB> tokens in this sample
|
| 57 |
+
eob_positions = torch.nonzero(sample_ids == eob_token_id).flatten()
|
| 58 |
+
|
| 59 |
+
# Calculate block lengths for this sample
|
| 60 |
+
if len(eob_positions) == 0:
|
| 61 |
+
# No EOB tokens, treat entire sample as one block
|
| 62 |
+
block_lengths = torch.tensor([length], device=input_ids.device)
|
| 63 |
+
else:
|
| 64 |
+
# Add start and end positions
|
| 65 |
+
# EOB is included in its block (boundary marker)
|
| 66 |
+
boundaries = torch.cat([
|
| 67 |
+
torch.tensor([0], device=input_ids.device),
|
| 68 |
+
eob_positions + 1, # +1 to include EOB token in block
|
| 69 |
+
torch.tensor([length], device=input_ids.device)
|
| 70 |
+
])
|
| 71 |
+
block_lengths = torch.diff(boundaries)
|
| 72 |
+
# Filter out 0-length blocks (happens when EOB is at the end of the sample)
|
| 73 |
+
block_lengths = block_lengths[block_lengths > 0]
|
| 74 |
+
|
| 75 |
+
current_sample_block_lengths.append(block_lengths)
|
| 76 |
+
start_idx = end_idx
|
| 77 |
+
|
| 78 |
+
all_batch_block_lengths.append(current_sample_block_lengths)
|
| 79 |
+
|
| 80 |
+
return all_batch_block_lengths
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def block_diff_mask_dynamic(b, h, q_idx, kv_idx, block_boundaries=None, n=None):
|
| 84 |
+
"""
|
| 85 |
+
Dynamic block diffusion mask using precomputed block boundaries.
|
| 86 |
+
|
| 87 |
+
This replaces the fixed block_size arithmetic with torch.searchsorted
|
| 88 |
+
to support variable-length blocks.
|
| 89 |
+
|
| 90 |
+
Args:
|
| 91 |
+
b: Batch index (unused in mask logic)
|
| 92 |
+
h: Head index (unused in mask logic)
|
| 93 |
+
q_idx: Query indices tensor
|
| 94 |
+
kv_idx: Key-value indices tensor
|
| 95 |
+
block_boundaries: Cumulative sum of block lengths, e.g., [0, 4, 12, 16]
|
| 96 |
+
This maps: tokens 0-3 → block 0, 4-11 → block 1, 12-15 → block 2
|
| 97 |
+
n: Number of denoised (clean) tokens
|
| 98 |
+
|
| 99 |
+
Returns:
|
| 100 |
+
Boolean attention mask (True = can attend)
|
| 101 |
+
|
| 102 |
+
The mask combines three types:
|
| 103 |
+
- M_BD (Block Diagonal): Self-attention within noised blocks
|
| 104 |
+
- M_OBC (Offset Block Causal): Cross-attention from noised to conditional context
|
| 105 |
+
- M_BC (Block Causal): Attention to denoised blocks
|
| 106 |
+
"""
|
| 107 |
+
# Map indices to block IDs (handling both Noisy 0..n-1 and Clean n..2n-1)
|
| 108 |
+
# We use modulo n to map Clean tokens back to their relative position
|
| 109 |
+
q_mod = q_idx % n
|
| 110 |
+
kv_mod = kv_idx % n
|
| 111 |
+
|
| 112 |
+
# Use searchsorted to find which block each index belongs to
|
| 113 |
+
# right=True ensures that [0, 4] maps 0,1,2,3 to the first interval
|
| 114 |
+
# We subtract 1 to get 0-based block indices
|
| 115 |
+
q_block_id = torch.searchsorted(block_boundaries, q_mod, right=True) - 1
|
| 116 |
+
kv_block_id = torch.searchsorted(block_boundaries, kv_mod, right=True) - 1
|
| 117 |
+
|
| 118 |
+
# Clamp to handle edge cases
|
| 119 |
+
q_block_id = torch.clamp(q_block_id, 0, len(block_boundaries) - 2)
|
| 120 |
+
kv_block_id = torch.clamp(kv_block_id, 0, len(block_boundaries) - 2)
|
| 121 |
+
|
| 122 |
+
# Identify Noisy vs Clean
|
| 123 |
+
# Noisy: < n (x0_flag = False)
|
| 124 |
+
# Clean: >= n (x0_flag = True)
|
| 125 |
+
is_clean_q = q_idx >= n
|
| 126 |
+
is_clean_kv = kv_idx >= n
|
| 127 |
+
|
| 128 |
+
# **1. Block Diagonal Mask (M_BD) **
|
| 129 |
+
# Self-attention within blocks (Noisy->Noisy, Clean->Clean)
|
| 130 |
+
M_BD = (q_block_id == kv_block_id) & (is_clean_q == is_clean_kv)
|
| 131 |
+
|
| 132 |
+
# **2. Offset Block-Causal Mask (M_OBC) **
|
| 133 |
+
# Noisy i attends to Clean j < i
|
| 134 |
+
# (Original code: block_q > block_kv & clean_kv & noisy_q)
|
| 135 |
+
M_OBC = (q_block_id > kv_block_id) & (is_clean_kv) & (~is_clean_q)
|
| 136 |
+
|
| 137 |
+
# **3. Block-Causal Mask (M_BC) **
|
| 138 |
+
# Clean i attends to Clean j <= i
|
| 139 |
+
M_BC = (q_block_id >= kv_block_id) & (is_clean_kv) & (is_clean_q)
|
| 140 |
+
|
| 141 |
+
# **4. Combine Masks **
|
| 142 |
+
return M_BD | M_OBC | M_BC
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def block_attn_mask_dynamic(
|
| 146 |
+
nested_block_lengths_list: List[List[torch.Tensor]],
|
| 147 |
+
device: torch.device
|
| 148 |
+
) -> torch.Tensor:
|
| 149 |
+
"""
|
| 150 |
+
Construct attention masks for variable-length blocks, handling packed sequences.
|
| 151 |
+
|
| 152 |
+
Args:
|
| 153 |
+
nested_block_lengths_list: List (batch) of Lists (samples) of Tensors (block lengths).
|
| 154 |
+
device: Device to create tensors on
|
| 155 |
+
|
| 156 |
+
Returns:
|
| 157 |
+
Attention mask tensor, shape (batch_size, total_seq_len*2, total_seq_len*2)
|
| 158 |
+
"""
|
| 159 |
+
masks = []
|
| 160 |
+
|
| 161 |
+
for sample_block_lengths_list in nested_block_lengths_list:
|
| 162 |
+
sample_masks = []
|
| 163 |
+
|
| 164 |
+
for block_lengths in sample_block_lengths_list:
|
| 165 |
+
# Calculate total sequence length for this sample
|
| 166 |
+
total_len = block_lengths.sum().item()
|
| 167 |
+
if total_len == 0:
|
| 168 |
+
continue
|
| 169 |
+
|
| 170 |
+
n = total_len # Number of clean tokens
|
| 171 |
+
|
| 172 |
+
# Create block boundaries (cumulative sum)
|
| 173 |
+
block_boundaries = torch.cat([
|
| 174 |
+
torch.tensor([0], device=device),
|
| 175 |
+
torch.cumsum(block_lengths, dim=0)
|
| 176 |
+
])
|
| 177 |
+
|
| 178 |
+
# Create index tensors for the full 2n x 2n mask
|
| 179 |
+
seq_len_doubled = total_len * 2
|
| 180 |
+
q_idx = torch.arange(seq_len_doubled, device=device)[:, None]
|
| 181 |
+
kv_idx = torch.arange(seq_len_doubled, device=device)[None, :]
|
| 182 |
+
|
| 183 |
+
# Generate mask using dynamic block boundaries
|
| 184 |
+
mask = block_diff_mask_dynamic(
|
| 185 |
+
b=None,
|
| 186 |
+
h=None,
|
| 187 |
+
q_idx=q_idx,
|
| 188 |
+
kv_idx=kv_idx,
|
| 189 |
+
block_boundaries=block_boundaries,
|
| 190 |
+
n=n
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
sample_masks.append(mask)
|
| 194 |
+
|
| 195 |
+
# Combine sample masks into a single block-diagonal mask for the batch item
|
| 196 |
+
if sample_masks:
|
| 197 |
+
row_mask = torch.block_diag(*sample_masks)
|
| 198 |
+
else:
|
| 199 |
+
# Should not happen if input is valid
|
| 200 |
+
row_mask = torch.zeros((0, 0), device=device, dtype=torch.bool)
|
| 201 |
+
|
| 202 |
+
masks.append(row_mask)
|
| 203 |
+
|
| 204 |
+
# Stack into batch
|
| 205 |
+
# We assume all row_masks have the same size (2 * seq_len)
|
| 206 |
+
# If not (due to padding differences?), we might need to pad them.
|
| 207 |
+
# But calculate_token_nums usually covers the whole seq_len including padding.
|
| 208 |
+
|
| 209 |
+
# Check sizes
|
| 210 |
+
sizes = [m.shape[0] for m in masks]
|
| 211 |
+
max_size = max(sizes)
|
| 212 |
+
|
| 213 |
+
padded_masks = []
|
| 214 |
+
for m in masks:
|
| 215 |
+
if m.shape[0] < max_size:
|
| 216 |
+
# Pad with False (no attention)
|
| 217 |
+
pad_size = max_size - m.shape[0]
|
| 218 |
+
m = torch.nn.functional.pad(m, (0, pad_size, 0, pad_size), value=False)
|
| 219 |
+
padded_masks.append(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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
|
| 3 |
+
# Code adapted from
|
| 4 |
+
# https://github.com/fla-org/flash-linear-attention/blob/main/fla/modules/fused_linear_cross_entropy.py
|
| 5 |
+
# Implementation of element-wise division of cross entropy loss
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Code adapted from
|
| 9 |
+
# https://github.com/linkedin/Liger-Kernel/blob/main/src/liger_kernel/ops/fused_linear_cross_entropy.py
|
| 10 |
+
|
| 11 |
+
from functools import partial
|
| 12 |
+
from typing import Optional, Tuple
|
| 13 |
+
|
| 14 |
+
import torch
|
| 15 |
+
import torch.nn as nn
|
| 16 |
+
import torch.nn.functional as F
|
| 17 |
+
import triton
|
| 18 |
+
import triton.language as tl
|
| 19 |
+
from torch.distributed import DeviceMesh
|
| 20 |
+
from torch.distributed.tensor import DTensor, Replicate, Shard, distribute_module
|
| 21 |
+
from torch.distributed.tensor.parallel import ParallelStyle
|
| 22 |
+
|
| 23 |
+
# The hard limit of TRITON_MAX_TENSOR_NUMEL is 1048576
|
| 24 |
+
# https://github.com/triton-lang/triton/blob/ba42a5c68fd0505f8c42f4202d53be0f8d9a5fe0/python/triton/language/core.py#L19
|
| 25 |
+
# However, setting limit as 65536 as in LayerNorm tutorial is faster because of less register spilling
|
| 26 |
+
# The optimal maximum block size depends on your hardware, your kernel, and your dtype
|
| 27 |
+
MAX_FUSED_SIZE = 65536 // 2
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@triton.heuristics({
|
| 31 |
+
'HAS_SCALE': lambda args: args['scale'] is not None
|
| 32 |
+
})
|
| 33 |
+
@triton.autotune(
|
| 34 |
+
configs=[
|
| 35 |
+
triton.Config({}, num_warps=num_warps)
|
| 36 |
+
for num_warps in [1, 2, 4, 8, 16, 32]
|
| 37 |
+
],
|
| 38 |
+
key=['D']
|
| 39 |
+
)
|
| 40 |
+
@triton.jit
|
| 41 |
+
def logsumexp_fwd_kernel(
|
| 42 |
+
x,
|
| 43 |
+
z,
|
| 44 |
+
scale,
|
| 45 |
+
D: tl.constexpr,
|
| 46 |
+
B: tl.constexpr,
|
| 47 |
+
HAS_SCALE: tl.constexpr
|
| 48 |
+
):
|
| 49 |
+
i_n, i_d = tl.program_id(0).to(tl.int64), tl.program_id(1).to(tl.int64)
|
| 50 |
+
o_d = i_d * B + tl.arange(0, B)
|
| 51 |
+
m_d = o_d < D
|
| 52 |
+
|
| 53 |
+
b_x = tl.load(x + i_n * D + o_d, mask=m_d, other=-float('inf'))
|
| 54 |
+
if HAS_SCALE:
|
| 55 |
+
b_x = b_x * scale
|
| 56 |
+
b_m = tl.max(b_x, 0)
|
| 57 |
+
b_z = tl.log(tl.sum(tl.exp(b_x - b_m), 0)) + b_m
|
| 58 |
+
tl.store(z + i_n * tl.cdiv(D, B) + i_d, b_z)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def logsumexp_fwd(
|
| 62 |
+
x,
|
| 63 |
+
scale: Optional[float] = None,
|
| 64 |
+
dtype: Optional[torch.dtype] = None
|
| 65 |
+
):
|
| 66 |
+
r"""
|
| 67 |
+
Compute the logsumexp of the input tensor over the last dimension.
|
| 68 |
+
|
| 69 |
+
Args:
|
| 70 |
+
x (Tensor):
|
| 71 |
+
The input tensor of any shape.
|
| 72 |
+
scale (Optional[float]):
|
| 73 |
+
The scale applied to the input tensor. Default: `None`.
|
| 74 |
+
dtype (Optional[torch.dtype]):
|
| 75 |
+
The data type of the output tensor. Default: `None`.
|
| 76 |
+
Returns:
|
| 77 |
+
Tensor: The logsumexp of the input tensor.
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
shape = x.shape
|
| 81 |
+
x = x.view(-1, shape[-1])
|
| 82 |
+
N, D = x.shape
|
| 83 |
+
B = min(triton.next_power_of_2(D), 64 * 1024)
|
| 84 |
+
ND = triton.cdiv(D, B)
|
| 85 |
+
|
| 86 |
+
z = x.new_empty(N, ND, dtype=torch.float)
|
| 87 |
+
logsumexp_fwd_kernel[(N, ND)](
|
| 88 |
+
x=x,
|
| 89 |
+
z=z,
|
| 90 |
+
scale=scale,
|
| 91 |
+
D=D,
|
| 92 |
+
B=B
|
| 93 |
+
)
|
| 94 |
+
z = z.logsumexp(-1).view(*shape[:-1])
|
| 95 |
+
if dtype is not None and dtype != torch.float:
|
| 96 |
+
z = z.to(dtype)
|
| 97 |
+
return z
|
| 98 |
+
|
| 99 |
+
@triton.jit
|
| 100 |
+
def cross_entropy_kernel(
|
| 101 |
+
logits,
|
| 102 |
+
lse,
|
| 103 |
+
target,
|
| 104 |
+
p_mask,
|
| 105 |
+
loss,
|
| 106 |
+
total,
|
| 107 |
+
ignore_index,
|
| 108 |
+
label_smoothing: tl.constexpr,
|
| 109 |
+
logit_scale: tl.constexpr,
|
| 110 |
+
reduction: tl.constexpr,
|
| 111 |
+
V: tl.constexpr,
|
| 112 |
+
BV: tl.constexpr
|
| 113 |
+
):
|
| 114 |
+
"""
|
| 115 |
+
This kernel computes both cross entropy loss and the gradient of the input.
|
| 116 |
+
We only consider hard label + mean reduction for now.
|
| 117 |
+
Please refer to https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html for the math.
|
| 118 |
+
|
| 119 |
+
Args:
|
| 120 |
+
logits:
|
| 121 |
+
Pointer to logits tensor.
|
| 122 |
+
lse:
|
| 123 |
+
Pointer to logsumexp tensor.
|
| 124 |
+
target: Pointer to target tensor.
|
| 125 |
+
loss:
|
| 126 |
+
Pointer to tensor to store the loss.
|
| 127 |
+
V (int):
|
| 128 |
+
The number of columns in the input tensor.
|
| 129 |
+
total (int):
|
| 130 |
+
The number of non-ignored classes.
|
| 131 |
+
ignore_index (int):
|
| 132 |
+
The index to ignore in the target.
|
| 133 |
+
label_smoothing (float):
|
| 134 |
+
The amount of smoothing when computing the loss, where 0.0 means no smoothing.
|
| 135 |
+
reduction (str):
|
| 136 |
+
The string for the reduction to apply
|
| 137 |
+
BV (int):
|
| 138 |
+
The block size for vocab.
|
| 139 |
+
"""
|
| 140 |
+
|
| 141 |
+
# https://github.com/triton-lang/triton/issues/1058
|
| 142 |
+
# If B*T*V is too large, i_n * stride will overflow out of int32, so we convert to int64
|
| 143 |
+
i_n = tl.program_id(0).to(tl.int64)
|
| 144 |
+
NV = tl.cdiv(V, BV)
|
| 145 |
+
|
| 146 |
+
# 1. Load target first because if the target is ignore_index, we can return right away
|
| 147 |
+
b_y = tl.load(target + i_n)
|
| 148 |
+
# load p_mask
|
| 149 |
+
b_p_mask = tl.load(p_mask + i_n)
|
| 150 |
+
|
| 151 |
+
# 2. locate the start index
|
| 152 |
+
logits += i_n * V
|
| 153 |
+
|
| 154 |
+
if b_y == ignore_index:
|
| 155 |
+
# set all x as 0
|
| 156 |
+
for i in range(0, V, BV):
|
| 157 |
+
o_v = i + tl.arange(0, BV)
|
| 158 |
+
tl.store(logits + o_v, 0.0, mask=o_v < V)
|
| 159 |
+
return
|
| 160 |
+
|
| 161 |
+
# Online softmax: 2 loads + 1 store (compared with 3 loads + 1 store for the safe softmax)
|
| 162 |
+
# Refer to Algorithm 3 in the paper: https://arxiv.org/pdf/1805.02867
|
| 163 |
+
|
| 164 |
+
# 3. [Online softmax] first pass: compute logsumexp
|
| 165 |
+
# we did this in anouter kernel
|
| 166 |
+
b_l = tl.load(logits + b_y) * logit_scale
|
| 167 |
+
b_lse = tl.load(lse + i_n)
|
| 168 |
+
|
| 169 |
+
# 4. Calculate the loss
|
| 170 |
+
# loss = lse - logits_l
|
| 171 |
+
# celoss = -log(q_y) = -log(softmax(x_y))
|
| 172 |
+
b_loss = (b_lse - b_l) / b_p_mask # Diffusion Scaled '1/t'
|
| 173 |
+
|
| 174 |
+
# Label smoothing is a general case of normal cross entropy
|
| 175 |
+
# See the full derivation at https://github.com/linkedin/Liger-Kernel/pull/198#issue-2503665310
|
| 176 |
+
b_z = 0.0
|
| 177 |
+
eps = label_smoothing / V
|
| 178 |
+
|
| 179 |
+
# We need tl.debug_barrier() as mentioned in
|
| 180 |
+
# https://github.com/triton-lang/triton/blob/ba42a5c68fd0505f8c42f4202d53be0f8d9a5fe0/python/triton/ops/cross_entropy.py#L34
|
| 181 |
+
tl.debug_barrier()
|
| 182 |
+
|
| 183 |
+
# 5. [Online Softmax] Second pass: compute gradients
|
| 184 |
+
# For 'mean' reduction, gradients are normalized by number of non-ignored elements
|
| 185 |
+
# dx_y = (softmax(x_y) - 1) / N
|
| 186 |
+
# dx_i = softmax(x_i) / N, i != y
|
| 187 |
+
# For label smoothing:
|
| 188 |
+
# dx_i = (softmax(x_y) - label_smoothing / V) / N, i != y
|
| 189 |
+
# dx_y = (softmax(x_y) - label_smoothing / V - (1 - label_smoothing)) / N
|
| 190 |
+
# = dx_i - (1 - label_smoothing) / N
|
| 191 |
+
for iv in range(0, NV):
|
| 192 |
+
o_v = iv * BV + tl.arange(0, BV)
|
| 193 |
+
b_logits = tl.load(logits + o_v, mask=o_v < V, other=float('-inf')) * logit_scale
|
| 194 |
+
if label_smoothing > 0:
|
| 195 |
+
# scale X beforehand to avoid overflow
|
| 196 |
+
b_z += tl.sum(tl.where(o_v < V, -eps * b_logits, 0.0))
|
| 197 |
+
b_p = (tl.exp(b_logits - b_lse) - eps) * logit_scale
|
| 198 |
+
b_p /= b_p_mask # 修改
|
| 199 |
+
if reduction == "mean":
|
| 200 |
+
b_p = b_p / total
|
| 201 |
+
tl.store(logits + o_v, b_p, mask=o_v < V)
|
| 202 |
+
|
| 203 |
+
tl.debug_barrier()
|
| 204 |
+
|
| 205 |
+
# Orginal loss = H(q, p), with label smoothing regularization = H(q', p) and (label_smoothing / V) = eps
|
| 206 |
+
# H(q', p) = (1 - label_smoothing) * H(q, p) + label_smoothing * H(u, p)
|
| 207 |
+
# = (1 - label_smoothing) * H(q, p) + eps * sum(logsoftmax(x_i))
|
| 208 |
+
# By using m (global max of xi) and d (sum of e^(xi-m)), we can simplify as:
|
| 209 |
+
# = (1 - label_smoothing) * H(q, p) + (-sum(x_i * eps) + label_smoothing * (m + logd))
|
| 210 |
+
# Refer to H(q', p) in section 7 of the paper:
|
| 211 |
+
# https://arxiv.org/pdf/1512.00567
|
| 212 |
+
# pytorch:
|
| 213 |
+
# https://github.com/pytorch/pytorch/blob/2981534f54d49fa3a9755c9b0855e7929c2527f0/aten/src/ATen/native/LossNLL.cpp#L516
|
| 214 |
+
# See full derivation at https://github.com/linkedin/Liger-Kernel/pull/198#issuecomment-2333753087
|
| 215 |
+
if label_smoothing > 0:
|
| 216 |
+
b_loss = b_loss * (1 - label_smoothing) + (b_z + label_smoothing * b_lse)
|
| 217 |
+
|
| 218 |
+
# 6. Specially handle the i==y case where `dx_y = (softmax(x_y) - (1 - label_smoothing) / N`
|
| 219 |
+
b_l = tl.load(logits + b_y)
|
| 220 |
+
|
| 221 |
+
# Normalize the loss by the number of non-ignored elements if reduction is "mean"
|
| 222 |
+
if reduction == 'mean':
|
| 223 |
+
b_loss = b_loss / total
|
| 224 |
+
# b_l += (label_smoothing - 1) / total * logit_scale
|
| 225 |
+
# b_l has already been divided by b_p_mask and total
|
| 226 |
+
b_l += (label_smoothing - 1) / b_p_mask / total * logit_scale
|
| 227 |
+
else:
|
| 228 |
+
# b_l += (label_smoothing - 1) * logit_scale
|
| 229 |
+
b_l += (label_smoothing - 1) / b_p_mask * logit_scale
|
| 230 |
+
|
| 231 |
+
tl.store(loss + i_n, b_loss)
|
| 232 |
+
tl.store(logits + b_y, b_l)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
@triton.jit
|
| 236 |
+
def elementwise_mul_kernel(
|
| 237 |
+
x,
|
| 238 |
+
g,
|
| 239 |
+
N: tl.constexpr,
|
| 240 |
+
B: tl.constexpr
|
| 241 |
+
):
|
| 242 |
+
"""
|
| 243 |
+
This function multiplies each element of the tensor pointed by x with the value pointed by g.
|
| 244 |
+
The multiplication is performed in-place on the tensor pointed by x.
|
| 245 |
+
|
| 246 |
+
Parameters:
|
| 247 |
+
x:
|
| 248 |
+
Pointer to the input tensor.
|
| 249 |
+
g:
|
| 250 |
+
Pointer to the gradient output value.
|
| 251 |
+
N (int):
|
| 252 |
+
The number of columns in the input tensor.
|
| 253 |
+
B (int):
|
| 254 |
+
The block size for Triton operations.
|
| 255 |
+
"""
|
| 256 |
+
|
| 257 |
+
# Get the program ID and convert it to int64 to avoid overflow
|
| 258 |
+
i_x = tl.program_id(0).to(tl.int64)
|
| 259 |
+
o_x = i_x * B + tl.arange(0, B)
|
| 260 |
+
|
| 261 |
+
# Load the gradient output value
|
| 262 |
+
b_g = tl.load(g)
|
| 263 |
+
b_x = tl.load(x + o_x, mask=o_x < N)
|
| 264 |
+
tl.store(x + o_x, b_x * b_g, mask=o_x < N)
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def fused_linear_cross_entropy_forward(
|
| 268 |
+
x: torch.Tensor,
|
| 269 |
+
target: torch.LongTensor,
|
| 270 |
+
weight: torch.Tensor,
|
| 271 |
+
bias: torch.Tensor = None,
|
| 272 |
+
p_mask: torch.Tensor = None,
|
| 273 |
+
ignore_index: int = -100,
|
| 274 |
+
label_smoothing: float = 0.0,
|
| 275 |
+
logit_scale: float = 1.0,
|
| 276 |
+
num_chunks: int = 8,
|
| 277 |
+
reduction: str = "mean"
|
| 278 |
+
):
|
| 279 |
+
device = x.device
|
| 280 |
+
# inputs have shape: [N, H]
|
| 281 |
+
# materialized activations will have shape: [N, V]
|
| 282 |
+
# the increase in memory = [N, V]
|
| 283 |
+
# reduction can be achieved by partitioning the number of tokens N into smaller chunks.
|
| 284 |
+
|
| 285 |
+
# ideally, we would like to achieve the same memory consumption as [N, H],
|
| 286 |
+
# so the expected chunk size should be:
|
| 287 |
+
# NC = ceil(V / H)
|
| 288 |
+
# C = ceil(N / NC)
|
| 289 |
+
# for ex: N = 4096*4, V = 32000, H = 4096 ==> NC = 8, C = ceil(N / NC) = 2048
|
| 290 |
+
N, H, V = *x.shape, weight.shape[0]
|
| 291 |
+
BV = min(MAX_FUSED_SIZE, triton.next_power_of_2(V))
|
| 292 |
+
# TODO: in real cases, we may need to limit the number of chunks NC to
|
| 293 |
+
# ensure the precisions of accumulated gradients
|
| 294 |
+
NC = min(num_chunks, triton.cdiv(V, H))
|
| 295 |
+
C = triton.next_power_of_2(triton.cdiv(N, NC))
|
| 296 |
+
NC = triton.cdiv(N, C)
|
| 297 |
+
|
| 298 |
+
# [N, H]
|
| 299 |
+
dx = torch.zeros_like(x, device=device)
|
| 300 |
+
# [V, H]
|
| 301 |
+
dw = torch.zeros_like(weight, device=device, dtype=torch.float) if weight is not None else None
|
| 302 |
+
# [V]
|
| 303 |
+
db = torch.zeros_like(bias, device=device, dtype=torch.float) if bias is not None else None
|
| 304 |
+
# [N]
|
| 305 |
+
loss = torch.zeros(N, device=device, dtype=torch.float)
|
| 306 |
+
|
| 307 |
+
total = target.ne(ignore_index).sum().item()
|
| 308 |
+
|
| 309 |
+
for ic in range(NC):
|
| 310 |
+
start, end = ic * C, min((ic + 1) * C, N)
|
| 311 |
+
# [C, N]
|
| 312 |
+
c_x = x[start:end]
|
| 313 |
+
# when doing matmul, use the original precision
|
| 314 |
+
# [C, V]
|
| 315 |
+
c_logits = F.linear(c_x, weight, bias)
|
| 316 |
+
c_target = target[start:end]
|
| 317 |
+
c_p_mask = p_mask[start:end]
|
| 318 |
+
# [C]
|
| 319 |
+
# keep lse in fp32 to maintain precision
|
| 320 |
+
c_lse = logsumexp_fwd(c_logits, scale=logit_scale, dtype=torch.float)
|
| 321 |
+
|
| 322 |
+
# unreduced loss
|
| 323 |
+
c_loss = loss[start:end]
|
| 324 |
+
|
| 325 |
+
# Here we calculate the gradient of c_logits in place so we can save memory.
|
| 326 |
+
cross_entropy_kernel[(c_logits.shape[0],)](
|
| 327 |
+
logits=c_logits,
|
| 328 |
+
lse=c_lse,
|
| 329 |
+
target=c_target,
|
| 330 |
+
p_mask=c_p_mask,
|
| 331 |
+
loss=c_loss,
|
| 332 |
+
total=total,
|
| 333 |
+
ignore_index=ignore_index,
|
| 334 |
+
label_smoothing=label_smoothing,
|
| 335 |
+
logit_scale=logit_scale,
|
| 336 |
+
reduction=reduction,
|
| 337 |
+
V=V,
|
| 338 |
+
BV=BV,
|
| 339 |
+
num_warps=32
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
# gradient of logits is computed in-place by the above triton kernel and is of shape: C x V
|
| 343 |
+
# thus dx should be of shape: C x H
|
| 344 |
+
dx[start:end] = torch.mm(c_logits, weight)
|
| 345 |
+
|
| 346 |
+
# keep dw in fp32 to maintain precision
|
| 347 |
+
if weight is not None:
|
| 348 |
+
dw += c_logits.t() @ c_x
|
| 349 |
+
|
| 350 |
+
if bias is not None:
|
| 351 |
+
torch.add(input=db, other=c_logits.sum(0), out=db)
|
| 352 |
+
|
| 353 |
+
loss = loss.sum()
|
| 354 |
+
if dw is not None:
|
| 355 |
+
dw = dw.to(weight)
|
| 356 |
+
if db is not None:
|
| 357 |
+
db = db.to(bias)
|
| 358 |
+
return loss, dx, dw, db
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
def fused_linear_cross_entropy_backward(
|
| 362 |
+
do: torch.Tensor,
|
| 363 |
+
dx: torch.Tensor,
|
| 364 |
+
dw: torch.Tensor,
|
| 365 |
+
db: torch.Tensor
|
| 366 |
+
):
|
| 367 |
+
# If cross entropy is the last layer, do is 1.0. Skip the mul to save time
|
| 368 |
+
if torch.ne(do, torch.tensor(1.0, device=do.device)):
|
| 369 |
+
# We use a Triton kernel instead of a PyTorch operation because modifying inputs in-place
|
| 370 |
+
# for gradient storage and backward multiple times causes anomalies with PyTorch but not with Triton.
|
| 371 |
+
N, H = dx.shape
|
| 372 |
+
B = min(MAX_FUSED_SIZE, triton.next_power_of_2(H))
|
| 373 |
+
|
| 374 |
+
elementwise_mul_kernel[(triton.cdiv(N * H, B),)](
|
| 375 |
+
x=dx,
|
| 376 |
+
g=do,
|
| 377 |
+
N=N*H,
|
| 378 |
+
B=B,
|
| 379 |
+
num_warps=32,
|
| 380 |
+
)
|
| 381 |
+
|
| 382 |
+
# handle dw
|
| 383 |
+
if dw is not None:
|
| 384 |
+
V, H = dw.shape
|
| 385 |
+
elementwise_mul_kernel[(triton.cdiv(V * H, B),)](
|
| 386 |
+
x=dw,
|
| 387 |
+
g=do,
|
| 388 |
+
N=V*H,
|
| 389 |
+
B=B,
|
| 390 |
+
num_warps=32,
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
if db is not None:
|
| 394 |
+
V = db.shape[0]
|
| 395 |
+
elementwise_mul_kernel[(triton.cdiv(V, B),)](
|
| 396 |
+
x=db,
|
| 397 |
+
g=do,
|
| 398 |
+
N=V,
|
| 399 |
+
B=B,
|
| 400 |
+
num_warps=32,
|
| 401 |
+
)
|
| 402 |
+
return dx, dw, db
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
class FusedLinearCrossEntropyFunction(torch.autograd.Function):
|
| 406 |
+
|
| 407 |
+
@staticmethod
|
| 408 |
+
def forward(
|
| 409 |
+
ctx,
|
| 410 |
+
x: torch.Tensor,
|
| 411 |
+
target: torch.LongTensor,
|
| 412 |
+
weight: torch.Tensor,
|
| 413 |
+
bias: torch.Tensor = None,
|
| 414 |
+
p_mask: torch.Tensor = None,
|
| 415 |
+
ignore_index: int = -100,
|
| 416 |
+
label_smoothing: float = 0.0,
|
| 417 |
+
logit_scale: float = 1.0,
|
| 418 |
+
num_chunks: int = 8,
|
| 419 |
+
reduction: str = "mean"
|
| 420 |
+
):
|
| 421 |
+
"""
|
| 422 |
+
Fusing the last linear layer with cross-entropy loss
|
| 423 |
+
Reference: https://github.com/mgmalek/efficient_cross_entropy
|
| 424 |
+
|
| 425 |
+
Handle the forward and backward pass of the final linear layer via cross-entropy loss by avoiding
|
| 426 |
+
the materialization of the large logits tensor. Since Cross Entropy Loss is the last layer, we can
|
| 427 |
+
compute the gradient at the forward pass. By doing so, we don't have to store the x and target
|
| 428 |
+
for the backward pass.
|
| 429 |
+
|
| 430 |
+
x (torch.Tensor): [batch_size * seq_len, hidden_size]
|
| 431 |
+
target (torch.LongTensor): [batch_size * seq_len]
|
| 432 |
+
where each value is in [0, vocab_size).
|
| 433 |
+
weight (torch.Tensor): [vocab_size, hidden_size]
|
| 434 |
+
where `vocab_size` is the number of classes.
|
| 435 |
+
bias (Optional[torch.Tensor]): [vocab_size]
|
| 436 |
+
where `vocab_size` is the number of classes.
|
| 437 |
+
p_mask(torch.Tensor): [batch_size * seq_len]
|
| 438 |
+
Its shape should be same as target.
|
| 439 |
+
ignore_index:
|
| 440 |
+
the index to ignore in the target.
|
| 441 |
+
label_smoothing:
|
| 442 |
+
the amount of smoothing when computing the loss, where 0.0 means no smoothing.
|
| 443 |
+
logit_scale: float = 1.0,
|
| 444 |
+
A scaling factor applied to the logits. Default: 1.0
|
| 445 |
+
num_chunks: int
|
| 446 |
+
The number of chunks to split the input tensor into for processing.
|
| 447 |
+
This can help optimize memory usage and computation speed.
|
| 448 |
+
Default: 8
|
| 449 |
+
reduction:
|
| 450 |
+
Specifies the reduction to apply to the output: 'mean' | 'sum'.
|
| 451 |
+
'mean': the weighted mean of the output is taken,
|
| 452 |
+
'sum': the output will be summed.
|
| 453 |
+
Default: 'mean'.
|
| 454 |
+
"""
|
| 455 |
+
loss, dx, dw, db = fused_linear_cross_entropy_forward(
|
| 456 |
+
x,
|
| 457 |
+
target,
|
| 458 |
+
weight,
|
| 459 |
+
bias,
|
| 460 |
+
p_mask,
|
| 461 |
+
ignore_index,
|
| 462 |
+
label_smoothing,
|
| 463 |
+
logit_scale,
|
| 464 |
+
num_chunks,
|
| 465 |
+
reduction
|
| 466 |
+
)
|
| 467 |
+
# downcast to dtype and store for backward
|
| 468 |
+
ctx.save_for_backward(
|
| 469 |
+
dx.detach(),
|
| 470 |
+
dw.detach() if weight is not None else None,
|
| 471 |
+
db.detach() if bias is not None else None,
|
| 472 |
+
)
|
| 473 |
+
return loss
|
| 474 |
+
|
| 475 |
+
@staticmethod
|
| 476 |
+
def backward(ctx, do):
|
| 477 |
+
dx, dw, db = ctx.saved_tensors
|
| 478 |
+
dx, dw, db = fused_linear_cross_entropy_backward(do, dx, dw, db)
|
| 479 |
+
# 10 gradients should be returned, with `p_mask` having no grads
|
| 480 |
+
# Check the number of arguments in the `forward` method
|
| 481 |
+
return dx, None, dw, db, None, None, None, None, None, None
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
def fused_linear_cross_entropy_loss(
|
| 485 |
+
x: torch.Tensor,
|
| 486 |
+
target: torch.LongTensor,
|
| 487 |
+
weight: torch.Tensor,
|
| 488 |
+
bias: torch.Tensor = None,
|
| 489 |
+
p_mask: torch.Tensor = None,
|
| 490 |
+
ignore_index: int = -100,
|
| 491 |
+
label_smoothing: float = 0.0,
|
| 492 |
+
logit_scale: float = 1.0,
|
| 493 |
+
num_chunks: int = 8,
|
| 494 |
+
reduction: str = "mean"
|
| 495 |
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
| 496 |
+
"""
|
| 497 |
+
Args:
|
| 498 |
+
x (torch.Tensor): [batch_size * seq_len, hidden_size]
|
| 499 |
+
target (torch.LongTensor): [batch_size * seq_len]
|
| 500 |
+
where each value is in [0, vocab_size).
|
| 501 |
+
weight (torch.Tensor): [vocab_size, hidden_size]
|
| 502 |
+
where `vocab_size` is the number of classes.
|
| 503 |
+
bias (Optional[torch.Tensor]): [vocab_size]
|
| 504 |
+
where `vocab_size` is the number of classes.
|
| 505 |
+
p_mask(torch.Tensor): [batch_size * seq_len]
|
| 506 |
+
Its shape should be same as target.
|
| 507 |
+
ignore_index: int.
|
| 508 |
+
If target == ignore_index, the loss is set to 0.0.
|
| 509 |
+
label_smoothing: float
|
| 510 |
+
logit_scale: float
|
| 511 |
+
A scaling factor applied to the logits. Default: 1.0
|
| 512 |
+
num_chunks: int
|
| 513 |
+
The number of chunks to split the input tensor into for processing.
|
| 514 |
+
This can help optimize memory usage and computation speed.
|
| 515 |
+
Default: 8
|
| 516 |
+
reduction:
|
| 517 |
+
Specifies the reduction to apply to the output: 'mean' | 'sum'.
|
| 518 |
+
'mean': the weighted mean of the output is taken,
|
| 519 |
+
'sum': the output will be summed.
|
| 520 |
+
Default: 'mean'.
|
| 521 |
+
Returns:
|
| 522 |
+
losses: [batch,], float
|
| 523 |
+
"""
|
| 524 |
+
return FusedLinearCrossEntropyFunction.apply(
|
| 525 |
+
x,
|
| 526 |
+
target,
|
| 527 |
+
weight,
|
| 528 |
+
bias,
|
| 529 |
+
p_mask,
|
| 530 |
+
ignore_index,
|
| 531 |
+
label_smoothing,
|
| 532 |
+
logit_scale,
|
| 533 |
+
num_chunks,
|
| 534 |
+
reduction
|
| 535 |
+
)
|
| 536 |
+
|
| 537 |
+
|
| 538 |
+
class FusedLinearDiffusionCrossEntropyLoss(nn.Module):
|
| 539 |
+
|
| 540 |
+
def __init__(
|
| 541 |
+
self,
|
| 542 |
+
ignore_index: int = -100,
|
| 543 |
+
label_smoothing: float = 0.0,
|
| 544 |
+
logit_scale: float = 1.0,
|
| 545 |
+
num_chunks: int = 8,
|
| 546 |
+
reduction: str = "mean"
|
| 547 |
+
):
|
| 548 |
+
"""
|
| 549 |
+
Args:
|
| 550 |
+
ignore_index: int.
|
| 551 |
+
If target == ignore_index, the loss is set to 0.0.
|
| 552 |
+
label_smoothing: float
|
| 553 |
+
logit_scale: float
|
| 554 |
+
A scaling factor applied to the logits. Default: 1.0
|
| 555 |
+
num_chunks: int
|
| 556 |
+
The number of chunks to split the input tensor into for processing.
|
| 557 |
+
This can help optimize memory usage and computation speed.
|
| 558 |
+
Default: 8
|
| 559 |
+
reduction:
|
| 560 |
+
Specifies the reduction to apply to the output: 'mean' | 'sum'.
|
| 561 |
+
'mean': the weighted mean of the output is taken,
|
| 562 |
+
'sum': the output will be summed.
|
| 563 |
+
Default: 'mean'.
|
| 564 |
+
"""
|
| 565 |
+
super().__init__()
|
| 566 |
+
|
| 567 |
+
assert reduction in ["mean", "sum"], f"reduction: {reduction} is not supported"
|
| 568 |
+
|
| 569 |
+
self.ignore_index = ignore_index
|
| 570 |
+
self.label_smoothing = label_smoothing
|
| 571 |
+
self.logit_scale = logit_scale
|
| 572 |
+
self.num_chunks = num_chunks
|
| 573 |
+
self.reduction = reduction
|
| 574 |
+
|
| 575 |
+
@torch.compiler.disable
|
| 576 |
+
def forward(
|
| 577 |
+
self,
|
| 578 |
+
x: torch.Tensor,
|
| 579 |
+
target: torch.LongTensor,
|
| 580 |
+
weight: torch.Tensor,
|
| 581 |
+
bias: Optional[torch.Tensor] = None,
|
| 582 |
+
p_mask: torch.Tensor = None,
|
| 583 |
+
eob_token_id: Optional[int] = None,
|
| 584 |
+
eob_weight: float = 1.0
|
| 585 |
+
):
|
| 586 |
+
"""
|
| 587 |
+
Args:
|
| 588 |
+
x (torch.Tensor): [batch_size, seq_len, hidden_size]
|
| 589 |
+
target (torch.LongTensor): [batch_size, seq_len]
|
| 590 |
+
where each value is in [0, V).
|
| 591 |
+
weight (torch.Tensor): [vocab_size, hidden_size]
|
| 592 |
+
where `vocab_size` is the number of classes.
|
| 593 |
+
bias (Optional[torch.Tensor]): [vocab_size]
|
| 594 |
+
where `vocab_size` is the number of classes.
|
| 595 |
+
p_mask(torch.Tensor): [batch_size, seq_len]
|
| 596 |
+
Its shape is same as target.
|
| 597 |
+
Shape: (1, packed_length) when varlen attn is used.
|
| 598 |
+
Returns:
|
| 599 |
+
loss
|
| 600 |
+
|
| 601 |
+
TODO:
|
| 602 |
+
follow https://github.com/ML-GSAI/LLaDA/blob/main/GUIDELINES.md#pre-training
|
| 603 |
+
```py
|
| 604 |
+
unreduced_loss /= p_mask
|
| 605 |
+
```
|
| 606 |
+
Scale the values of `unreduced_loss at different positions
|
| 607 |
+
"""
|
| 608 |
+
if p_mask is None:
|
| 609 |
+
p_mask = torch.ones_like(target, dtype=torch.float, device=x.device)
|
| 610 |
+
|
| 611 |
+
# Apply EOB weight if provided
|
| 612 |
+
if eob_token_id is not None and eob_weight != 1.0:
|
| 613 |
+
# We want to multiply the loss of EOB tokens by eob_weight.
|
| 614 |
+
# The kernel calculates loss = unreduced_loss / p_mask.
|
| 615 |
+
# So to get loss * eob_weight, we need to divide p_mask by eob_weight.
|
| 616 |
+
# p_mask_new = p_mask / eob_weight
|
| 617 |
+
# loss_new = unreduced_loss / (p_mask / eob_weight) = (unreduced_loss / p_mask) * eob_weight
|
| 618 |
+
|
| 619 |
+
# Create a mask for EOB tokens
|
| 620 |
+
is_eob = (target == eob_token_id)
|
| 621 |
+
if is_eob.any():
|
| 622 |
+
# We need to modify p_mask. Since p_mask might be reused or is a view, let's clone it if needed.
|
| 623 |
+
# However, p_mask is usually created fresh in forward_add_noise_packed.
|
| 624 |
+
# But to be safe and avoid side effects if it's used elsewhere (unlikely), we can modify in place if it's not a leaf.
|
| 625 |
+
# p_mask is likely a tensor from the graph.
|
| 626 |
+
|
| 627 |
+
# Let's modify it. Note: p_mask shape matches target shape here.
|
| 628 |
+
# We use a float mask to avoid in-place modification issues if possible, or just modify.
|
| 629 |
+
# p_mask = p_mask.clone() # Safer
|
| 630 |
+
|
| 631 |
+
# Actually, we can just do:
|
| 632 |
+
# p_mask[is_eob] = p_mask[is_eob] / eob_weight
|
| 633 |
+
# But p_mask might be on a different device or flattened?
|
| 634 |
+
# target is flattened below. Let's do it before flattening or after?
|
| 635 |
+
# The code flattens target and p_mask below.
|
| 636 |
+
pass
|
| 637 |
+
|
| 638 |
+
x = x.contiguous().view(-1, x.shape[-1])
|
| 639 |
+
target = target.contiguous().view(-1)
|
| 640 |
+
weight = weight.contiguous()
|
| 641 |
+
bias = bias.contiguous() if bias else None
|
| 642 |
+
p_mask = p_mask.contiguous().view(-1)
|
| 643 |
+
|
| 644 |
+
# Apply EOB weight (after flattening to be safe and consistent)
|
| 645 |
+
if eob_token_id is not None and eob_weight != 1.0:
|
| 646 |
+
is_eob = (target == eob_token_id)
|
| 647 |
+
if is_eob.any():
|
| 648 |
+
# We divide p_mask by eob_weight to effectively multiply loss by eob_weight
|
| 649 |
+
# We use a multiplier tensor to avoid in-place ops on p_mask if it causes issues,
|
| 650 |
+
# but modifying p_mask is the most direct way for the kernel.
|
| 651 |
+
# We need to ensure p_mask is floating point.
|
| 652 |
+
p_mask = p_mask.clone() # Clone to avoid modifying the input tensor
|
| 653 |
+
p_mask[is_eob] = p_mask[is_eob] / eob_weight
|
| 654 |
+
|
| 655 |
+
l, d = x.shape
|
| 656 |
+
assert l == target.shape[0] == p_mask.shape[0], f"{x.shape=}, {target.shape=}, {p_mask.shape=}"
|
| 657 |
+
|
| 658 |
+
loss = fused_linear_cross_entropy_loss(
|
| 659 |
+
x,
|
| 660 |
+
target,
|
| 661 |
+
weight=weight,
|
| 662 |
+
bias=bias,
|
| 663 |
+
p_mask=p_mask,
|
| 664 |
+
ignore_index=self.ignore_index,
|
| 665 |
+
label_smoothing=self.label_smoothing,
|
| 666 |
+
logit_scale=self.logit_scale,
|
| 667 |
+
num_chunks=self.num_chunks,
|
| 668 |
+
reduction=self.reduction
|
| 669 |
+
)
|
| 670 |
+
return loss
|
| 671 |
+
|
| 672 |
+
|
| 673 |
+
class LinearLossParallel(ParallelStyle):
|
| 674 |
+
def __init__(
|
| 675 |
+
self,
|
| 676 |
+
*,
|
| 677 |
+
sequence_dim: int = 1,
|
| 678 |
+
use_local_output: bool = False,
|
| 679 |
+
):
|
| 680 |
+
super().__init__()
|
| 681 |
+
|
| 682 |
+
self.sequence_sharding = (Shard(sequence_dim),)
|
| 683 |
+
self.use_local_output = use_local_output
|
| 684 |
+
|
| 685 |
+
@staticmethod
|
| 686 |
+
def _prepare_input_fn(sequence_sharding, mod, inputs, device_mesh):
|
| 687 |
+
x, target, weight, bias = inputs
|
| 688 |
+
|
| 689 |
+
if not isinstance(x, DTensor):
|
| 690 |
+
# assume the input passed in already sharded on the sequence dim and create the DTensor
|
| 691 |
+
x = DTensor.from_local(x, device_mesh, sequence_sharding)
|
| 692 |
+
if x.placements != sequence_sharding:
|
| 693 |
+
x = x.redistribute(placements=sequence_sharding, async_op=True)
|
| 694 |
+
if not isinstance(target, DTensor):
|
| 695 |
+
target = DTensor.from_local(target, device_mesh, [Replicate()])
|
| 696 |
+
if target.placements != sequence_sharding:
|
| 697 |
+
target = target.redistribute(placements=sequence_sharding, async_op=True)
|
| 698 |
+
|
| 699 |
+
if not isinstance(weight, DTensor):
|
| 700 |
+
weight = DTensor.from_local(weight, device_mesh, [Replicate()])
|
| 701 |
+
if weight.placements != [Replicate()]:
|
| 702 |
+
# we replicate the weight/bias in FLCE
|
| 703 |
+
weight = weight.redistribute(placements=[Replicate()], async_op=True)
|
| 704 |
+
|
| 705 |
+
if bias is not None and not isinstance(bias, DTensor):
|
| 706 |
+
bias = DTensor.from_local(bias, device_mesh, [Replicate()])
|
| 707 |
+
if bias is not None and bias.placements != [Replicate()]:
|
| 708 |
+
bias = bias.redistribute(placements=[Replicate()], async_op=True)
|
| 709 |
+
|
| 710 |
+
return x.to_local(), target.to_local(), weight.to_local(), bias.to_local() if bias is not None else bias
|
| 711 |
+
|
| 712 |
+
@staticmethod
|
| 713 |
+
def _prepare_output_fn(use_local_output, mod, outputs, device_mesh):
|
| 714 |
+
return outputs.to_local() if use_local_output else outputs
|
| 715 |
+
|
| 716 |
+
def _apply(self, module: nn.Module, device_mesh: DeviceMesh) -> nn.Module:
|
| 717 |
+
return distribute_module(
|
| 718 |
+
module,
|
| 719 |
+
device_mesh,
|
| 720 |
+
partition_fn=None,
|
| 721 |
+
input_fn=partial(self._prepare_input_fn, self.sequence_sharding),
|
| 722 |
+
output_fn=partial(self._prepare_output_fn, self.use_local_output)
|
| 723 |
+
)
|
generation_config.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 151643,
|
| 3 |
+
"do_sample": true,
|
| 4 |
+
"eos_token_id": [
|
| 5 |
+
151645,
|
| 6 |
+
151643
|
| 7 |
+
],
|
| 8 |
+
"pad_token_id": 151643,
|
| 9 |
+
"temperature": 0.6,
|
| 10 |
+
"top_k": 20,
|
| 11 |
+
"top_p": 0.95,
|
| 12 |
+
"transformers_version": "4.52.4"
|
| 13 |
+
}
|
latest
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
global_step1549
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-00001-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:785fe86ef4cad56e5e4c4fdb04046db53e3f94e3c0eabf07fa63c8bb8b4bc6c9
|
| 3 |
+
size 4967215360
|
model-00002-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:929f19e3802619c326f0d972f3824328bea9b978ca8918f8b86fcd9799e8d62d
|
| 3 |
+
size 3855679144
|
model.safetensors.index.json
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 8822848512
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"lm_head.weight": "model-00002-of-00002.safetensors",
|
| 7 |
+
"model.embed_tokens.weight": "model-00001-of-00002.safetensors",
|
| 8 |
+
"model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 9 |
+
"model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 10 |
+
"model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 11 |
+
"model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 12 |
+
"model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 13 |
+
"model.layers.0.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 14 |
+
"model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 15 |
+
"model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 16 |
+
"model.layers.0.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 17 |
+
"model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 18 |
+
"model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 19 |
+
"model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 20 |
+
"model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 21 |
+
"model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 22 |
+
"model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 23 |
+
"model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 24 |
+
"model.layers.1.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 25 |
+
"model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 26 |
+
"model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 27 |
+
"model.layers.1.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 28 |
+
"model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 29 |
+
"model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 30 |
+
"model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 31 |
+
"model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 32 |
+
"model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 33 |
+
"model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 34 |
+
"model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 35 |
+
"model.layers.10.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 36 |
+
"model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 37 |
+
"model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 38 |
+
"model.layers.10.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 39 |
+
"model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 40 |
+
"model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 41 |
+
"model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 42 |
+
"model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 43 |
+
"model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 44 |
+
"model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 45 |
+
"model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 46 |
+
"model.layers.11.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 47 |
+
"model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 48 |
+
"model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 49 |
+
"model.layers.11.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 50 |
+
"model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 51 |
+
"model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 52 |
+
"model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 53 |
+
"model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 54 |
+
"model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 55 |
+
"model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 56 |
+
"model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 57 |
+
"model.layers.12.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 58 |
+
"model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 59 |
+
"model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 60 |
+
"model.layers.12.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 61 |
+
"model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 62 |
+
"model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 63 |
+
"model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 64 |
+
"model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 65 |
+
"model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 66 |
+
"model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 67 |
+
"model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 68 |
+
"model.layers.13.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 69 |
+
"model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 70 |
+
"model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 71 |
+
"model.layers.13.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 72 |
+
"model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 73 |
+
"model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 74 |
+
"model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 75 |
+
"model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 76 |
+
"model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 77 |
+
"model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 78 |
+
"model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 79 |
+
"model.layers.14.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 80 |
+
"model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 81 |
+
"model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 82 |
+
"model.layers.14.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 83 |
+
"model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 84 |
+
"model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 85 |
+
"model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 86 |
+
"model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 87 |
+
"model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 88 |
+
"model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 89 |
+
"model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 90 |
+
"model.layers.15.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 91 |
+
"model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 92 |
+
"model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 93 |
+
"model.layers.15.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 94 |
+
"model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 95 |
+
"model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 96 |
+
"model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 97 |
+
"model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 98 |
+
"model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 99 |
+
"model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 100 |
+
"model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 101 |
+
"model.layers.16.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 102 |
+
"model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 103 |
+
"model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 104 |
+
"model.layers.16.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 105 |
+
"model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 106 |
+
"model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 107 |
+
"model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 108 |
+
"model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 109 |
+
"model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 110 |
+
"model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 111 |
+
"model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 112 |
+
"model.layers.17.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 113 |
+
"model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 114 |
+
"model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 115 |
+
"model.layers.17.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 116 |
+
"model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 117 |
+
"model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 118 |
+
"model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 119 |
+
"model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 120 |
+
"model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 121 |
+
"model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 122 |
+
"model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 123 |
+
"model.layers.18.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 124 |
+
"model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 125 |
+
"model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 126 |
+
"model.layers.18.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 127 |
+
"model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 128 |
+
"model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 129 |
+
"model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 130 |
+
"model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 131 |
+
"model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 132 |
+
"model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 133 |
+
"model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 134 |
+
"model.layers.19.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 135 |
+
"model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 136 |
+
"model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 137 |
+
"model.layers.19.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 138 |
+
"model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 139 |
+
"model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 140 |
+
"model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 141 |
+
"model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 142 |
+
"model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 143 |
+
"model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 144 |
+
"model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 145 |
+
"model.layers.2.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 146 |
+
"model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 147 |
+
"model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 148 |
+
"model.layers.2.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 149 |
+
"model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 150 |
+
"model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 151 |
+
"model.layers.20.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 152 |
+
"model.layers.20.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 153 |
+
"model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 154 |
+
"model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 155 |
+
"model.layers.20.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 156 |
+
"model.layers.20.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 157 |
+
"model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 158 |
+
"model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 159 |
+
"model.layers.20.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 160 |
+
"model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 161 |
+
"model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 162 |
+
"model.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 163 |
+
"model.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 164 |
+
"model.layers.21.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 165 |
+
"model.layers.21.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 166 |
+
"model.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 167 |
+
"model.layers.21.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 168 |
+
"model.layers.21.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 169 |
+
"model.layers.21.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 170 |
+
"model.layers.21.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 171 |
+
"model.layers.21.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 172 |
+
"model.layers.21.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 173 |
+
"model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 174 |
+
"model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 175 |
+
"model.layers.22.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 176 |
+
"model.layers.22.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 177 |
+
"model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 178 |
+
"model.layers.22.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 179 |
+
"model.layers.22.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 180 |
+
"model.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 181 |
+
"model.layers.22.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 182 |
+
"model.layers.22.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 183 |
+
"model.layers.22.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 184 |
+
"model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 185 |
+
"model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 186 |
+
"model.layers.23.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 187 |
+
"model.layers.23.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 188 |
+
"model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 189 |
+
"model.layers.23.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 190 |
+
"model.layers.23.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 191 |
+
"model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 192 |
+
"model.layers.23.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 193 |
+
"model.layers.23.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 194 |
+
"model.layers.23.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 195 |
+
"model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 196 |
+
"model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 197 |
+
"model.layers.24.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 198 |
+
"model.layers.24.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 199 |
+
"model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 200 |
+
"model.layers.24.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 201 |
+
"model.layers.24.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 202 |
+
"model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 203 |
+
"model.layers.24.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 204 |
+
"model.layers.24.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 205 |
+
"model.layers.24.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 206 |
+
"model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 207 |
+
"model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 208 |
+
"model.layers.25.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 209 |
+
"model.layers.25.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 210 |
+
"model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 211 |
+
"model.layers.25.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 212 |
+
"model.layers.25.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 213 |
+
"model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 214 |
+
"model.layers.25.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 215 |
+
"model.layers.25.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 216 |
+
"model.layers.25.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 217 |
+
"model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 218 |
+
"model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 219 |
+
"model.layers.26.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 220 |
+
"model.layers.26.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 221 |
+
"model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 222 |
+
"model.layers.26.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 223 |
+
"model.layers.26.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 224 |
+
"model.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 225 |
+
"model.layers.26.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 226 |
+
"model.layers.26.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 227 |
+
"model.layers.26.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 228 |
+
"model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 229 |
+
"model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 230 |
+
"model.layers.27.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 231 |
+
"model.layers.27.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 232 |
+
"model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 233 |
+
"model.layers.27.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 234 |
+
"model.layers.27.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 235 |
+
"model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 236 |
+
"model.layers.27.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 237 |
+
"model.layers.27.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 238 |
+
"model.layers.27.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 239 |
+
"model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 240 |
+
"model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 241 |
+
"model.layers.28.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 242 |
+
"model.layers.28.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 243 |
+
"model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 244 |
+
"model.layers.28.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 245 |
+
"model.layers.28.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 246 |
+
"model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 247 |
+
"model.layers.28.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 248 |
+
"model.layers.28.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 249 |
+
"model.layers.28.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 250 |
+
"model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 251 |
+
"model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 252 |
+
"model.layers.29.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 253 |
+
"model.layers.29.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 254 |
+
"model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 255 |
+
"model.layers.29.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 256 |
+
"model.layers.29.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 257 |
+
"model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 258 |
+
"model.layers.29.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 259 |
+
"model.layers.29.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 260 |
+
"model.layers.29.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 261 |
+
"model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 262 |
+
"model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 263 |
+
"model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 264 |
+
"model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 265 |
+
"model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 266 |
+
"model.layers.3.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 267 |
+
"model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 268 |
+
"model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 269 |
+
"model.layers.3.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 270 |
+
"model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 271 |
+
"model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 272 |
+
"model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 273 |
+
"model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 274 |
+
"model.layers.30.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 275 |
+
"model.layers.30.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 276 |
+
"model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 277 |
+
"model.layers.30.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 278 |
+
"model.layers.30.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 279 |
+
"model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 280 |
+
"model.layers.30.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 281 |
+
"model.layers.30.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 282 |
+
"model.layers.30.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 283 |
+
"model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 284 |
+
"model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 285 |
+
"model.layers.31.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 286 |
+
"model.layers.31.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 287 |
+
"model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 288 |
+
"model.layers.31.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 289 |
+
"model.layers.31.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 290 |
+
"model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 291 |
+
"model.layers.31.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 292 |
+
"model.layers.31.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 293 |
+
"model.layers.31.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 294 |
+
"model.layers.32.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 295 |
+
"model.layers.32.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 296 |
+
"model.layers.32.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 297 |
+
"model.layers.32.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 298 |
+
"model.layers.32.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 299 |
+
"model.layers.32.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 300 |
+
"model.layers.32.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 301 |
+
"model.layers.32.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 302 |
+
"model.layers.32.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 303 |
+
"model.layers.32.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 304 |
+
"model.layers.32.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 305 |
+
"model.layers.33.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 306 |
+
"model.layers.33.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 307 |
+
"model.layers.33.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 308 |
+
"model.layers.33.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 309 |
+
"model.layers.33.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 310 |
+
"model.layers.33.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 311 |
+
"model.layers.33.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 312 |
+
"model.layers.33.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 313 |
+
"model.layers.33.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 314 |
+
"model.layers.33.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 315 |
+
"model.layers.33.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 316 |
+
"model.layers.34.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 317 |
+
"model.layers.34.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 318 |
+
"model.layers.34.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 319 |
+
"model.layers.34.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 320 |
+
"model.layers.34.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 321 |
+
"model.layers.34.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 322 |
+
"model.layers.34.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 323 |
+
"model.layers.34.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 324 |
+
"model.layers.34.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 325 |
+
"model.layers.34.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 326 |
+
"model.layers.34.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 327 |
+
"model.layers.35.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 328 |
+
"model.layers.35.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 329 |
+
"model.layers.35.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 330 |
+
"model.layers.35.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 331 |
+
"model.layers.35.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 332 |
+
"model.layers.35.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 333 |
+
"model.layers.35.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 334 |
+
"model.layers.35.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 335 |
+
"model.layers.35.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 336 |
+
"model.layers.35.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 337 |
+
"model.layers.35.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 338 |
+
"model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 339 |
+
"model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 340 |
+
"model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 341 |
+
"model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 342 |
+
"model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 343 |
+
"model.layers.4.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 344 |
+
"model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 345 |
+
"model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 346 |
+
"model.layers.4.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 347 |
+
"model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 348 |
+
"model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 349 |
+
"model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 350 |
+
"model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 351 |
+
"model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 352 |
+
"model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 353 |
+
"model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 354 |
+
"model.layers.5.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 355 |
+
"model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 356 |
+
"model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 357 |
+
"model.layers.5.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 358 |
+
"model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 359 |
+
"model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 360 |
+
"model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 361 |
+
"model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 362 |
+
"model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 363 |
+
"model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 364 |
+
"model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 365 |
+
"model.layers.6.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 366 |
+
"model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 367 |
+
"model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 368 |
+
"model.layers.6.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 369 |
+
"model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 370 |
+
"model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 371 |
+
"model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 372 |
+
"model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 373 |
+
"model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 374 |
+
"model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 375 |
+
"model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 376 |
+
"model.layers.7.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 377 |
+
"model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 378 |
+
"model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 379 |
+
"model.layers.7.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 380 |
+
"model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 381 |
+
"model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 382 |
+
"model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 383 |
+
"model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 384 |
+
"model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 385 |
+
"model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 386 |
+
"model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 387 |
+
"model.layers.8.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 388 |
+
"model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 389 |
+
"model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 390 |
+
"model.layers.8.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 391 |
+
"model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 392 |
+
"model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 393 |
+
"model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 394 |
+
"model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 395 |
+
"model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 396 |
+
"model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 397 |
+
"model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 398 |
+
"model.layers.9.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 399 |
+
"model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 400 |
+
"model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 401 |
+
"model.layers.9.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 402 |
+
"model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 403 |
+
"model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 404 |
+
"model.norm.weight": "model-00002-of-00002.safetensors"
|
| 405 |
+
}
|
| 406 |
+
}
|
modeling_sdar.py
ADDED
|
@@ -0,0 +1,1245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is modified based on https://github.com/huggingface/transformers/blob/v4.52.4/src/transformers/models/qwen3/modeling_qwen3.py.
|
| 2 |
+
#
|
| 3 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 4 |
+
# This file was automatically generated from src/transformers/models/qwen3/modular_qwen3.py.
|
| 5 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 6 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 7 |
+
# modular_qwen3.py file directly. One of our CI enforces this.
|
| 8 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 9 |
+
# coding=utf-8
|
| 10 |
+
# Copyright 2025 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
| 11 |
+
#
|
| 12 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 13 |
+
# you may not use this file except in compliance with the License.
|
| 14 |
+
# You may obtain a copy of the License at
|
| 15 |
+
#
|
| 16 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 17 |
+
#
|
| 18 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 19 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 20 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 21 |
+
# See the License for the specific language governing permissions and
|
| 22 |
+
# limitations under the License.
|
| 23 |
+
|
| 24 |
+
from typing import Optional, Tuple, Union, List
|
| 25 |
+
|
| 26 |
+
import torch
|
| 27 |
+
from torch import nn
|
| 28 |
+
from einops import rearrange
|
| 29 |
+
|
| 30 |
+
from transformers.activations import ACT2FN
|
| 31 |
+
from transformers.cache_utils import Cache, DynamicCache, SlidingWindowCache, StaticCache
|
| 32 |
+
from transformers.generation import GenerationMixin
|
| 33 |
+
from transformers.integrations import use_kernel_forward_from_hub
|
| 34 |
+
from transformers.modeling_attn_mask_utils import AttentionMaskConverter
|
| 35 |
+
from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
|
| 36 |
+
from transformers.modeling_layers import GradientCheckpointingLayer
|
| 37 |
+
from transformers.modeling_outputs import (
|
| 38 |
+
BaseModelOutputWithPast,
|
| 39 |
+
CausalLMOutputWithPast,
|
| 40 |
+
)
|
| 41 |
+
from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
|
| 42 |
+
from transformers.modeling_utils import PreTrainedModel
|
| 43 |
+
from transformers.processing_utils import Unpack
|
| 44 |
+
from transformers.utils import LossKwargs, auto_docstring, can_return_tuple, is_torch_flex_attn_available, logging
|
| 45 |
+
from .configuration_sdar import SDARConfig
|
| 46 |
+
from .fused_linear_diffusion_cross_entropy import FusedLinearDiffusionCrossEntropyLoss
|
| 47 |
+
from .dynamic_blocks_utils import calculate_block_nums_from_eob, block_attn_mask_dynamic
|
| 48 |
+
|
| 49 |
+
from flash_attn.ops.triton.layer_norm import rms_norm_fn as flash_rms_norm
|
| 50 |
+
|
| 51 |
+
import torch.nn.functional as F
|
| 52 |
+
try:
|
| 53 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
| 54 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input
|
| 55 |
+
except:
|
| 56 |
+
pass
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
from liger_kernel.ops.swiglu import LigerSiLUMulFunction # noqa: F401
|
| 60 |
+
liger_kernel_is_available = True
|
| 61 |
+
except ImportError:
|
| 62 |
+
liger_kernel_is_available = False
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
if is_torch_flex_attn_available():
|
| 66 |
+
from torch.nn.attention.flex_attention import BlockMask, create_block_mask, flex_attention
|
| 67 |
+
from transformers.integrations.flex_attention import make_flex_block_causal_mask
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
logger = logging.get_logger(__name__)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def modify_padded_position_ids_2d(position_ids: torch.LongTensor) -> torch.LongTensor:
|
| 74 |
+
"""
|
| 75 |
+
This function uses fully vectorized PyTorch operations to modify the packed position_ids of a batch.
|
| 76 |
+
It assumes that the input is a 2D Tensor, shape (batch_size, sequence_length).
|
| 77 |
+
It will independently process each row in the batch.
|
| 78 |
+
|
| 79 |
+
Args:
|
| 80 |
+
position_ids: a 2D Tensor, shape (batch_size, sequence_length).
|
| 81 |
+
|
| 82 |
+
Returns:
|
| 83 |
+
the modified position_ids Tensor, shape (batch_size, sequence_length).
|
| 84 |
+
"""
|
| 85 |
+
if position_ids.dim() != 2:
|
| 86 |
+
raise ValueError(f"Input tensor must be 2D, but got {position_ids.dim()} dimensions.")
|
| 87 |
+
|
| 88 |
+
batch_size, seq_len = position_ids.shape
|
| 89 |
+
device = position_ids.device
|
| 90 |
+
|
| 91 |
+
col_indices = torch.arange(seq_len, device=device, dtype=position_ids.dtype).expand(batch_size, -1)
|
| 92 |
+
mask = (position_ids != 0)
|
| 93 |
+
|
| 94 |
+
masked_indices = col_indices * mask
|
| 95 |
+
last_nonzero_idx = torch.max(masked_indices, dim=1).values
|
| 96 |
+
has_nonzero = torch.any(mask, dim=1)
|
| 97 |
+
pad_start_idx = torch.where(has_nonzero, last_nonzero_idx + 1, torch.tensor(0, device=device, dtype=position_ids.dtype))
|
| 98 |
+
|
| 99 |
+
padding_mask = col_indices >= pad_start_idx.unsqueeze(1)
|
| 100 |
+
new_pad_values = col_indices - pad_start_idx.unsqueeze(1)
|
| 101 |
+
position_ids = torch.where(padding_mask, new_pad_values, position_ids)
|
| 102 |
+
|
| 103 |
+
return position_ids
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def calculate_token_nums(position_ids: torch.Tensor):
|
| 107 |
+
"""
|
| 108 |
+
This function uses PyTorch to efficiently calculate the length of each packed sequence in a batch.
|
| 109 |
+
|
| 110 |
+
Args:
|
| 111 |
+
position_ids (torch.Tensor): a 2D Tensor, shape (batch_size, sequence_length).
|
| 112 |
+
For example: tensor([[0,1,2,3,4,0,1,2,3,4,5,0,1,2,3,0,0,0]])
|
| 113 |
+
Returns:
|
| 114 |
+
list[list[int]]: a nested list, containing the length of each sequence in each batch item.
|
| 115 |
+
For example: [[5, 6, 4, 1, 1, 1]]
|
| 116 |
+
"""
|
| 117 |
+
if position_ids.dim() != 2:
|
| 118 |
+
raise ValueError(f"The input must be a 2D Tensor, but got {position_ids.dim()}D")
|
| 119 |
+
|
| 120 |
+
all_lengths = []
|
| 121 |
+
|
| 122 |
+
# we process the batch by batch item by batch item. Because the number of sequence lengths in each row is different (ragged),
|
| 123 |
+
# so loop is the most efficient and clear
|
| 124 |
+
# the op in loop is fully vectorize
|
| 125 |
+
for pids_row in position_ids:
|
| 126 |
+
# get the total length of the current row
|
| 127 |
+
seq_len = pids_row.shape[0]
|
| 128 |
+
|
| 129 |
+
# 1. find the indices of all elements that are equal to 0
|
| 130 |
+
# pids_row == 0 Tensor: [True, False, ..., True, ...]
|
| 131 |
+
# torch.nonzero will return index of these zero
|
| 132 |
+
# .flatten() will change the shape from (N, 1) to (N,)
|
| 133 |
+
zero_indices = torch.nonzero(pids_row == 0).flatten()
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
# it is very important for calculate last seq length
|
| 137 |
+
# note : same device (cpu/cuda)
|
| 138 |
+
split_points = torch.cat([
|
| 139 |
+
zero_indices,
|
| 140 |
+
torch.tensor([seq_len], device=pids_row.device, dtype=zero_indices.dtype)
|
| 141 |
+
])
|
| 142 |
+
|
| 143 |
+
# 3. compute difference , get length
|
| 144 |
+
# torch.diff([a, b, c, d]) will return [b-a, c-b, d-c]
|
| 145 |
+
lengths = torch.diff(split_points)
|
| 146 |
+
|
| 147 |
+
all_lengths.append(lengths)
|
| 148 |
+
|
| 149 |
+
return all_lengths
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def forward_add_noise_packed(
|
| 153 |
+
inputs_ids: torch.Tensor,
|
| 154 |
+
num_tokens_list: List[torch.Tensor],
|
| 155 |
+
prompt_mask: torch.Tensor,
|
| 156 |
+
mask_id: int,
|
| 157 |
+
eob_token_id: Optional[int] = None,
|
| 158 |
+
eps: float = 1e-3,
|
| 159 |
+
max_tries: int = 10,
|
| 160 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 161 |
+
"""
|
| 162 |
+
This function adds noise to the token IDs of a batch of packed sequences.
|
| 163 |
+
|
| 164 |
+
This function keeps the logic of generating independent random noise rates for each logical sample (concatenated within each batch item).
|
| 165 |
+
It will randomly replace some token IDs with mask_id.
|
| 166 |
+
This process will avoid the positions marked by prompt_mask.
|
| 167 |
+
|
| 168 |
+
Args:
|
| 169 |
+
inputs_ids (torch.Tensor):
|
| 170 |
+
the token ID tensor, shape (bsz, total_tokens), the token IDs of the packed sequences.
|
| 171 |
+
num_tokens_list (List[torch.Tensor]):
|
| 172 |
+
a list of tensors, length is bsz. Each tensor records the length of each logical sample in the corresponding batch item. For example: [tensor([len1, len2]), tensor([len3, len4, len5])].
|
| 173 |
+
prompt_mask (torch.Tensor):
|
| 174 |
+
a boolean tensor, shape (bsz, total_tokens), True positions represent prompt, should not add noise.
|
| 175 |
+
mask_id (int):
|
| 176 |
+
the ID of the mask token to replace.
|
| 177 |
+
eob_token_id (int, optional):
|
| 178 |
+
the ID of the EOB token. If provided, EOB tokens will ALWAYS be masked.
|
| 179 |
+
eps (float):
|
| 180 |
+
a small value, used to prevent the noise rate t from being exactly 0, ensure p_mask > 0.
|
| 181 |
+
max_tries (int):
|
| 182 |
+
the maximum number of attempts to ensure at least one non-prompt token is masked for each batch item.
|
| 183 |
+
|
| 184 |
+
Returns:
|
| 185 |
+
Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 186 |
+
- noisy_input_ids (torch.Tensor):
|
| 187 |
+
the token ID tensor, shape (bsz, total_tokens).
|
| 188 |
+
- final_masked_indices (torch.Tensor):
|
| 189 |
+
a boolean tensor, shape (bsz, total_tokens), True positions represent the positions that are actually masked.
|
| 190 |
+
- p_masks (torch.Tensor):
|
| 191 |
+
a one-dimensional tensor, containing the actual noise rates of the tokens that are masked.
|
| 192 |
+
"""
|
| 193 |
+
# 1. validate and get shape
|
| 194 |
+
bsz, total_tokens = inputs_ids.shape
|
| 195 |
+
device = inputs_ids.device
|
| 196 |
+
|
| 197 |
+
# validate the consistency of the input
|
| 198 |
+
assert len(num_tokens_list) == bsz, f"num_tokens_list 的长度 ({len(num_tokens_list)}) 必须等于 bsz ({bsz})"
|
| 199 |
+
assert prompt_mask.shape == (bsz, total_tokens), f"prompt_mask 形状不匹配, 期望 {(bsz, total_tokens)}, 得到 {prompt_mask.shape}"
|
| 200 |
+
|
| 201 |
+
noisy_ids_list = []
|
| 202 |
+
final_masked_indices_list = []
|
| 203 |
+
p_masks_per_token_list = []
|
| 204 |
+
|
| 205 |
+
# 2. iterate with loop. it is efficient because length is different
|
| 206 |
+
for i in range(bsz):
|
| 207 |
+
# get the data of the current batch item
|
| 208 |
+
current_ids = inputs_ids[i:i+1] # shape: (1, total_tokens)
|
| 209 |
+
current_num_tokens = num_tokens_list[i]
|
| 210 |
+
current_prompt_mask = prompt_mask[i:i+1] # shape: (1, total_tokens)
|
| 211 |
+
|
| 212 |
+
num_samples_in_item = len(current_num_tokens)
|
| 213 |
+
# validate the consistency of the token number in the current batch item
|
| 214 |
+
assert total_tokens == torch.sum(current_num_tokens), \
|
| 215 |
+
f"the sum of num_tokens in batch item {i} ({torch.sum(current_num_tokens)}) does not match total_tokens ({total_tokens})"
|
| 216 |
+
|
| 217 |
+
eligible_for_masking = ~current_prompt_mask
|
| 218 |
+
|
| 219 |
+
# if no token can be masked, use the original input and set p_mask to eps
|
| 220 |
+
if not eligible_for_masking.any():
|
| 221 |
+
noisy_ids_list.append(current_ids)
|
| 222 |
+
final_masked_indices_list.append(torch.zeros_like(current_prompt_mask, dtype=torch.bool))
|
| 223 |
+
# the shape of p_mask_per_token should be (1, total_tokens) for subsequent concatenation
|
| 224 |
+
p_masks_per_token_list.append(torch.full((1, total_tokens), eps, device=device, dtype=torch.float))
|
| 225 |
+
continue
|
| 226 |
+
|
| 227 |
+
# --- try to generate mask, ensure at least one token is masked ---
|
| 228 |
+
final_masked_indices_item = torch.zeros_like(current_prompt_mask, dtype=torch.bool)
|
| 229 |
+
p_mask_per_token = None
|
| 230 |
+
|
| 231 |
+
for _ in range(max_tries):
|
| 232 |
+
# generate a independent noise rate t for each logical sample
|
| 233 |
+
t = torch.rand(num_samples_in_item, device=device)
|
| 234 |
+
p_mask_per_sample = (1 - eps) * t + eps
|
| 235 |
+
|
| 236 |
+
# extend the noise rate of each sample to all tokens
|
| 237 |
+
p_mask_per_token_1d = torch.repeat_interleave(p_mask_per_sample, current_num_tokens)
|
| 238 |
+
p_mask_per_token = p_mask_per_token_1d.unsqueeze(0) # shape: (1, total_tokens)
|
| 239 |
+
|
| 240 |
+
# generate random mask based on the noise rate
|
| 241 |
+
masked_indices = torch.rand_like(p_mask_per_token) < p_mask_per_token
|
| 242 |
+
|
| 243 |
+
# Note: We do NOT force EOB tokens to always be masked.
|
| 244 |
+
# The eob_weight parameter in the loss function (default 0.1) handles
|
| 245 |
+
# reducing the loss contribution of EOB tokens.
|
| 246 |
+
# Allowing probabilistic masking lets the model learn natural EOB patterns.
|
| 247 |
+
|
| 248 |
+
# apply prompt mask,ensure prompt is not mask
|
| 249 |
+
final_masked_indices_item = masked_indices & eligible_for_masking
|
| 250 |
+
|
| 251 |
+
# if at least one token is masked, break the loop
|
| 252 |
+
if final_masked_indices_item.any():
|
| 253 |
+
break
|
| 254 |
+
|
| 255 |
+
# if max_tries , still not mask any token ( very low propobility),force mask one token
|
| 256 |
+
if not final_masked_indices_item.any():
|
| 257 |
+
eligible_indices = torch.nonzero(eligible_for_masking.squeeze(0), as_tuple=True)[0]
|
| 258 |
+
if len(eligible_indices) > 0:
|
| 259 |
+
# random choose one to mask
|
| 260 |
+
random_choice = torch.randint(0, len(eligible_indices), (1,)).item()
|
| 261 |
+
force_mask_idx = eligible_indices[random_choice]
|
| 262 |
+
final_masked_indices_item[0, force_mask_idx] = True
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
# generate noisy IDs based on the final mask
|
| 266 |
+
noisy_ids_item = torch.where(
|
| 267 |
+
final_masked_indices_item,
|
| 268 |
+
mask_id,
|
| 269 |
+
current_ids
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
# save the result of the current batch item
|
| 273 |
+
noisy_ids_list.append(noisy_ids_item)
|
| 274 |
+
final_masked_indices_list.append(final_masked_indices_item)
|
| 275 |
+
p_masks_per_token_list.append(p_mask_per_token)
|
| 276 |
+
|
| 277 |
+
# 3. stack the results in the list into the final batch tensor
|
| 278 |
+
noisy_input_ids = torch.cat(noisy_ids_list, dim=0)
|
| 279 |
+
final_masked_indices = torch.cat(final_masked_indices_list, dim=0)
|
| 280 |
+
p_mask_full = torch.cat(p_masks_per_token_list, dim=0)
|
| 281 |
+
|
| 282 |
+
# 4. extract the noise rate corresponding to the masked positions
|
| 283 |
+
p_masks = p_mask_full[final_masked_indices]
|
| 284 |
+
|
| 285 |
+
return noisy_input_ids, final_masked_indices, p_masks
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
def block_diff_mask(b, h, q_idx, kv_idx, block_size=None, n=None):
|
| 289 |
+
"""
|
| 290 |
+
Constructs the specialized block diffusion attention mask for training
|
| 291 |
+
composed of three masks:
|
| 292 |
+
- **Block Diagonal Mask (M_BD)**: Self-attention within noised blocks
|
| 293 |
+
- **Offset Block Causal Mask (M_OBC)**: Cross-attention for conditional context
|
| 294 |
+
- **Block Causal Mask (M_BC)**: Attention to update x0
|
| 295 |
+
|
| 296 |
+
Args:
|
| 297 |
+
b, h: Batch and head indices (ignored for mask logic).
|
| 298 |
+
q_idx, kv_idx: Query and Key indices.
|
| 299 |
+
seq_len: Total sequence length.
|
| 300 |
+
block_size: Defines the block structure.
|
| 301 |
+
|
| 302 |
+
Returns:
|
| 303 |
+
A boolean attention mask.
|
| 304 |
+
"""
|
| 305 |
+
|
| 306 |
+
# Indicate whether token belongs to xt or x0
|
| 307 |
+
x0_flag_q = q_idx >= n
|
| 308 |
+
x0_flag_kv = kv_idx >= n
|
| 309 |
+
|
| 310 |
+
# Compute block indices
|
| 311 |
+
block_q = torch.where(
|
| 312 |
+
x0_flag_q == 1, (q_idx - n) // block_size, q_idx // block_size
|
| 313 |
+
)
|
| 314 |
+
block_kv = torch.where(
|
| 315 |
+
x0_flag_kv == 1, (kv_idx - n) // block_size, kv_idx // block_size
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
# **1. Block Diagonal Mask (M_BD) **
|
| 319 |
+
block_diagonal = (block_q == block_kv) & (x0_flag_q == x0_flag_kv)
|
| 320 |
+
|
| 321 |
+
# **2. Offset Block-Causal Mask (M_OBC) **
|
| 322 |
+
offset_block_causal = (block_q > block_kv) & (
|
| 323 |
+
x0_flag_kv == 1) & (x0_flag_q == 0)
|
| 324 |
+
|
| 325 |
+
# **3. Block-Causal Mask (M_BC) **
|
| 326 |
+
block_causal = (block_q >= block_kv) & (x0_flag_kv == 1) & (x0_flag_q == 1)
|
| 327 |
+
|
| 328 |
+
# **4. Combine Masks **
|
| 329 |
+
return block_diagonal | offset_block_causal | block_causal
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
def block_attn_mask(num_tokens, block_size, device):
|
| 333 |
+
masks = []
|
| 334 |
+
for i in range(len(num_tokens)):
|
| 335 |
+
cur_masks = []
|
| 336 |
+
for num in num_tokens[i]:
|
| 337 |
+
# return n*n instead of 2n*2n
|
| 338 |
+
single_mask = block_diff_mask(
|
| 339 |
+
b=None,
|
| 340 |
+
h=None,
|
| 341 |
+
q_idx=torch.arange(num * 2, device=device)[:, None],
|
| 342 |
+
kv_idx=torch.arange(num * 2, device=device)[None, :],
|
| 343 |
+
block_size=block_size,
|
| 344 |
+
n=num,
|
| 345 |
+
)
|
| 346 |
+
cur_masks.append(single_mask)
|
| 347 |
+
masks.append(torch.block_diag(*cur_masks))
|
| 348 |
+
masks = torch.stack(masks, dim=0)
|
| 349 |
+
return masks
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
@torch.compile(fullgraph=True, mode="max-autotune-no-cudagraphs")
|
| 353 |
+
def fused_flex_attention(query, key, value, attention_mask, **kwargs):
|
| 354 |
+
return flex_attention(query, key, value, block_mask=attention_mask, **kwargs)
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
@use_kernel_forward_from_hub("RMSNorm")
|
| 358 |
+
class SDARRMSNorm(nn.Module):
|
| 359 |
+
def __init__(self, hidden_size, eps=1e-6):
|
| 360 |
+
"""
|
| 361 |
+
SDARRMSNorm is equivalent to T5LayerNorm
|
| 362 |
+
"""
|
| 363 |
+
super().__init__()
|
| 364 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 365 |
+
self.variance_epsilon = eps
|
| 366 |
+
|
| 367 |
+
def forward(self, hidden_states):
|
| 368 |
+
return flash_rms_norm(
|
| 369 |
+
hidden_states, weight=self.weight, bias=None, eps=self.variance_epsilon)
|
| 370 |
+
'''
|
| 371 |
+
input_dtype = hidden_states.dtype
|
| 372 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 373 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 374 |
+
hidden_states = hidden_states * \
|
| 375 |
+
torch.rsqrt(variance + self.variance_epsilon)
|
| 376 |
+
return self.weight * hidden_states.to(input_dtype)
|
| 377 |
+
'''
|
| 378 |
+
|
| 379 |
+
def extra_repr(self):
|
| 380 |
+
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
class SDARMLP(nn.Module):
|
| 384 |
+
def __init__(self, config):
|
| 385 |
+
super().__init__()
|
| 386 |
+
self.config = config
|
| 387 |
+
self.hidden_size = config.hidden_size
|
| 388 |
+
self.intermediate_size = config.intermediate_size
|
| 389 |
+
self.gate_proj = nn.Linear(
|
| 390 |
+
self.hidden_size, self.intermediate_size, bias=False)
|
| 391 |
+
self.up_proj = nn.Linear(
|
| 392 |
+
self.hidden_size, self.intermediate_size, bias=False)
|
| 393 |
+
self.down_proj = nn.Linear(
|
| 394 |
+
self.intermediate_size, self.hidden_size, bias=False)
|
| 395 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
| 396 |
+
|
| 397 |
+
def forward(self, x):
|
| 398 |
+
if liger_kernel_is_available:
|
| 399 |
+
return self.down_proj(LigerSiLUMulFunction.apply(self.gate_proj(x), self.up_proj(x)))
|
| 400 |
+
else:
|
| 401 |
+
down_proj = self.down_proj(self.act_fn(
|
| 402 |
+
self.gate_proj(x)) * self.up_proj(x))
|
| 403 |
+
return down_proj
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
def rotate_half(x):
|
| 407 |
+
"""Rotates half the hidden dims of the input."""
|
| 408 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 409 |
+
x2 = x[..., x.shape[-1] // 2:]
|
| 410 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 414 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 415 |
+
|
| 416 |
+
Args:
|
| 417 |
+
q (`torch.Tensor`): The query tensor.
|
| 418 |
+
k (`torch.Tensor`): The key tensor.
|
| 419 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 420 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 421 |
+
position_ids (`torch.Tensor`, *optional*):
|
| 422 |
+
Deprecated and unused.
|
| 423 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 424 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 425 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 426 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 427 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 428 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 429 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 430 |
+
Returns:
|
| 431 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 432 |
+
"""
|
| 433 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 434 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 435 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 436 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 437 |
+
return q_embed, k_embed
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 441 |
+
"""
|
| 442 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 443 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 444 |
+
"""
|
| 445 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 446 |
+
if n_rep == 1:
|
| 447 |
+
return hidden_states
|
| 448 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(
|
| 449 |
+
batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 450 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
def eager_attention_forward(
|
| 454 |
+
module: nn.Module,
|
| 455 |
+
query: torch.Tensor,
|
| 456 |
+
key: torch.Tensor,
|
| 457 |
+
value: torch.Tensor,
|
| 458 |
+
attention_mask: Optional[torch.Tensor],
|
| 459 |
+
scaling: float,
|
| 460 |
+
dropout: float = 0.0,
|
| 461 |
+
**kwargs,
|
| 462 |
+
):
|
| 463 |
+
key_states = repeat_kv(key, module.num_key_value_groups)
|
| 464 |
+
value_states = repeat_kv(value, module.num_key_value_groups)
|
| 465 |
+
|
| 466 |
+
attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
|
| 467 |
+
if attention_mask is not None:
|
| 468 |
+
causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
|
| 469 |
+
attn_weights = attn_weights + causal_mask
|
| 470 |
+
|
| 471 |
+
attn_weights = nn.functional.softmax(
|
| 472 |
+
attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
|
| 473 |
+
attn_weights = nn.functional.dropout(
|
| 474 |
+
attn_weights, p=dropout, training=module.training)
|
| 475 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 476 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 477 |
+
|
| 478 |
+
return attn_output, attn_weights
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
class SDARAttention(nn.Module):
|
| 482 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 483 |
+
|
| 484 |
+
def __init__(self, config: SDARConfig, layer_idx: int):
|
| 485 |
+
super().__init__()
|
| 486 |
+
self.config = config
|
| 487 |
+
self.layer_idx = layer_idx
|
| 488 |
+
self.head_dim = getattr(
|
| 489 |
+
config, "head_dim", config.hidden_size // config.num_attention_heads)
|
| 490 |
+
self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
|
| 491 |
+
self.scaling = self.head_dim**-0.5
|
| 492 |
+
self.attention_dropout = config.attention_dropout
|
| 493 |
+
self.is_causal = True
|
| 494 |
+
|
| 495 |
+
self.hidden_size = config.hidden_size
|
| 496 |
+
self.num_attention_heads = config.num_attention_heads
|
| 497 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 498 |
+
|
| 499 |
+
self.q_proj = nn.Linear(
|
| 500 |
+
config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
|
| 501 |
+
)
|
| 502 |
+
self.k_proj = nn.Linear(
|
| 503 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 504 |
+
)
|
| 505 |
+
self.v_proj = nn.Linear(
|
| 506 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 507 |
+
)
|
| 508 |
+
self.o_proj = nn.Linear(
|
| 509 |
+
config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
|
| 510 |
+
)
|
| 511 |
+
# unlike olmo, only on the head dim!
|
| 512 |
+
self.q_norm = SDARRMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
| 513 |
+
# thus post q_norm does not need reshape
|
| 514 |
+
self.k_norm = SDARRMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
| 515 |
+
self.sliding_window = config.sliding_window
|
| 516 |
+
if not (
|
| 517 |
+
self.config.use_sliding_window
|
| 518 |
+
and getattr(self.config, "sliding_window", None) is not None
|
| 519 |
+
and self.layer_idx >= self.config.max_window_layers
|
| 520 |
+
):
|
| 521 |
+
self.sliding_window = None
|
| 522 |
+
|
| 523 |
+
def forward(
|
| 524 |
+
self,
|
| 525 |
+
hidden_states: torch.Tensor,
|
| 526 |
+
position_embeddings: Tuple[torch.Tensor, torch.Tensor],
|
| 527 |
+
attention_mask: Optional[torch.Tensor],
|
| 528 |
+
past_key_value: Optional[Cache] = None,
|
| 529 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 530 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 531 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 532 |
+
input_shape = hidden_states.shape[:-1]
|
| 533 |
+
bsz, q_len = input_shape
|
| 534 |
+
hidden_shape = (*input_shape, -1, self.head_dim)
|
| 535 |
+
|
| 536 |
+
query_states = self.q_norm(self.q_proj(
|
| 537 |
+
hidden_states).view(hidden_shape)).transpose(1, 2)
|
| 538 |
+
key_states = self.k_norm(self.k_proj(
|
| 539 |
+
hidden_states).view(hidden_shape)).transpose(1, 2)
|
| 540 |
+
value_states = self.v_proj(hidden_states).view(
|
| 541 |
+
hidden_shape).transpose(1, 2)
|
| 542 |
+
|
| 543 |
+
cos, sin = position_embeddings
|
| 544 |
+
query_states, key_states = apply_rotary_pos_emb(
|
| 545 |
+
query_states, key_states, cos, sin)
|
| 546 |
+
|
| 547 |
+
if past_key_value is not None and kwargs.get("store_kv", False):
|
| 548 |
+
# sin and cos are specific to RoPE models; cache_position needed for the static cache
|
| 549 |
+
key_states, value_states = past_key_value.update(
|
| 550 |
+
key_states, value_states, self.layer_idx)
|
| 551 |
+
elif past_key_value is not None and not kwargs.get("store_kv", False) and len(past_key_value) > self.layer_idx:
|
| 552 |
+
# only retrive, do not store kv
|
| 553 |
+
past_key_states, past_value_states = past_key_value[self.layer_idx]
|
| 554 |
+
key_states = torch.cat(
|
| 555 |
+
[past_key_states, key_states], dim=-2)
|
| 556 |
+
value_states = torch.cat(
|
| 557 |
+
[past_value_states, value_states], dim=-2)
|
| 558 |
+
|
| 559 |
+
if self.training:
|
| 560 |
+
attn_output, attn_weights = fused_flex_attention(
|
| 561 |
+
query=query_states,
|
| 562 |
+
key=key_states,
|
| 563 |
+
value=value_states,
|
| 564 |
+
attention_mask=attention_mask,
|
| 565 |
+
enable_gqa=True,
|
| 566 |
+
scale=self.scaling,
|
| 567 |
+
return_lse=True
|
| 568 |
+
)
|
| 569 |
+
attn_weights = attn_weights.to(
|
| 570 |
+
value_states.dtype) if attn_weights is not None else None
|
| 571 |
+
attn_output = rearrange(attn_output, 'b h l d -> b l (h d)')
|
| 572 |
+
else:
|
| 573 |
+
attention_mask = attention_mask.bool() if attention_mask is not None else None
|
| 574 |
+
attn_weights = None
|
| 575 |
+
if torch.all(attention_mask): # decoding
|
| 576 |
+
query_states = query_states.transpose(1, 2)
|
| 577 |
+
key_states = key_states.transpose(1, 2)
|
| 578 |
+
value_states = value_states.transpose(1, 2)
|
| 579 |
+
attn_output = flash_attn_func(
|
| 580 |
+
query_states,
|
| 581 |
+
key_states,
|
| 582 |
+
value_states,
|
| 583 |
+
causal=False,
|
| 584 |
+
softmax_scale=self.scaling
|
| 585 |
+
)
|
| 586 |
+
attn_output = rearrange(attn_output, 'b l h d -> b l (h d)')
|
| 587 |
+
else: # prefilling
|
| 588 |
+
attn_output = F.scaled_dot_product_attention(
|
| 589 |
+
query=query_states,
|
| 590 |
+
key=key_states,
|
| 591 |
+
value=value_states,
|
| 592 |
+
attn_mask=attention_mask,
|
| 593 |
+
is_causal=False,
|
| 594 |
+
scale=self.scaling,
|
| 595 |
+
enable_gqa=True
|
| 596 |
+
)
|
| 597 |
+
attn_output = rearrange(attn_output, 'b h l d -> b l (h d)')
|
| 598 |
+
attn_output = self.o_proj(attn_output)
|
| 599 |
+
return attn_output, attn_weights # , attn_weights
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
class SDARDecoderLayer(GradientCheckpointingLayer):
|
| 603 |
+
def __init__(self, config: SDARConfig, layer_idx: int):
|
| 604 |
+
super().__init__()
|
| 605 |
+
self.hidden_size = config.hidden_size
|
| 606 |
+
self.self_attn = SDARAttention(config=config, layer_idx=layer_idx)
|
| 607 |
+
self.mlp = SDARMLP(config)
|
| 608 |
+
self.input_layernorm = SDARRMSNorm(
|
| 609 |
+
config.hidden_size, eps=config.rms_norm_eps)
|
| 610 |
+
self.post_attention_layernorm = SDARRMSNorm(
|
| 611 |
+
config.hidden_size, eps=config.rms_norm_eps)
|
| 612 |
+
if (
|
| 613 |
+
config.sliding_window and config._attn_implementation != "flash_attention_2"
|
| 614 |
+
): # diff with Llama is this warning
|
| 615 |
+
logger.warning_once(
|
| 616 |
+
f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
|
| 617 |
+
"unexpected results may be encountered."
|
| 618 |
+
)
|
| 619 |
+
|
| 620 |
+
def forward(
|
| 621 |
+
self,
|
| 622 |
+
hidden_states: torch.Tensor,
|
| 623 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 624 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 625 |
+
past_key_value: Optional[Cache] = None,
|
| 626 |
+
output_attentions: Optional[bool] = False,
|
| 627 |
+
use_cache: Optional[bool] = False,
|
| 628 |
+
store_kv: Optional[bool] = False,
|
| 629 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 630 |
+
# necessary, but kept here for BC
|
| 631 |
+
position_embeddings: Optional[Tuple[torch.Tensor,
|
| 632 |
+
torch.Tensor]] = None,
|
| 633 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 634 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
| 635 |
+
residual = hidden_states
|
| 636 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 637 |
+
|
| 638 |
+
# Self Attention
|
| 639 |
+
hidden_states, self_attn_weights = self.self_attn(
|
| 640 |
+
hidden_states=hidden_states,
|
| 641 |
+
attention_mask=attention_mask,
|
| 642 |
+
position_ids=position_ids,
|
| 643 |
+
past_key_value=past_key_value,
|
| 644 |
+
output_attentions=output_attentions,
|
| 645 |
+
use_cache=use_cache,
|
| 646 |
+
store_kv=store_kv,
|
| 647 |
+
cache_position=cache_position,
|
| 648 |
+
position_embeddings=position_embeddings,
|
| 649 |
+
**kwargs,
|
| 650 |
+
)
|
| 651 |
+
hidden_states = residual + hidden_states
|
| 652 |
+
|
| 653 |
+
# Fully Connected
|
| 654 |
+
residual = hidden_states
|
| 655 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 656 |
+
hidden_states = self.mlp(hidden_states)
|
| 657 |
+
hidden_states = residual + hidden_states
|
| 658 |
+
|
| 659 |
+
outputs = (hidden_states,)
|
| 660 |
+
if output_attentions:
|
| 661 |
+
outputs += (self_attn_weights,)
|
| 662 |
+
|
| 663 |
+
return outputs
|
| 664 |
+
|
| 665 |
+
|
| 666 |
+
@auto_docstring
|
| 667 |
+
class SDARPreTrainedModel(PreTrainedModel):
|
| 668 |
+
config_class = SDARConfig
|
| 669 |
+
base_model_prefix = "model"
|
| 670 |
+
supports_gradient_checkpointing = True
|
| 671 |
+
_no_split_modules = ["SDARDecoderLayer"]
|
| 672 |
+
_skip_keys_device_placement = ["past_key_values"]
|
| 673 |
+
_supports_flash_attn_2 = True
|
| 674 |
+
_supports_sdpa = True
|
| 675 |
+
_supports_flex_attn = True
|
| 676 |
+
_supports_cache_class = True
|
| 677 |
+
_supports_quantized_cache = True
|
| 678 |
+
_supports_static_cache = True
|
| 679 |
+
_supports_attention_backend = True
|
| 680 |
+
|
| 681 |
+
def _init_weights(self, module):
|
| 682 |
+
std = self.config.initializer_range
|
| 683 |
+
if isinstance(module, nn.Linear):
|
| 684 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 685 |
+
if module.bias is not None:
|
| 686 |
+
module.bias.data.zero_()
|
| 687 |
+
elif isinstance(module, nn.Embedding):
|
| 688 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 689 |
+
if module.padding_idx is not None:
|
| 690 |
+
module.weight.data[module.padding_idx].zero_()
|
| 691 |
+
elif isinstance(module, SDARRMSNorm):
|
| 692 |
+
module.weight.data.fill_(1.0)
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
class SDARRotaryEmbedding(nn.Module):
|
| 696 |
+
def __init__(self, config: SDARConfig, device=None):
|
| 697 |
+
super().__init__()
|
| 698 |
+
# BC: "rope_type" was originally "type"
|
| 699 |
+
if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
|
| 700 |
+
self.rope_type = config.rope_scaling.get(
|
| 701 |
+
"rope_type", config.rope_scaling.get("type"))
|
| 702 |
+
else:
|
| 703 |
+
self.rope_type = "default"
|
| 704 |
+
self.max_seq_len_cached = config.max_position_embeddings
|
| 705 |
+
self.original_max_seq_len = config.max_position_embeddings
|
| 706 |
+
|
| 707 |
+
self.config = config
|
| 708 |
+
self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
|
| 709 |
+
|
| 710 |
+
inv_freq, self.attention_scaling = self.rope_init_fn(
|
| 711 |
+
self.config, device)
|
| 712 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 713 |
+
self.original_inv_freq = self.inv_freq
|
| 714 |
+
|
| 715 |
+
@torch.no_grad()
|
| 716 |
+
# power user: used with advanced RoPE types (e.g. dynamic rope)
|
| 717 |
+
@dynamic_rope_update
|
| 718 |
+
def forward(self, x, position_ids):
|
| 719 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(
|
| 720 |
+
position_ids.shape[0], -1, 1).to(x.device)
|
| 721 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 722 |
+
|
| 723 |
+
device_type = x.device.type if isinstance(
|
| 724 |
+
x.device.type, str) and x.device.type != "mps" else "cpu"
|
| 725 |
+
with torch.autocast(device_type=device_type, enabled=False): # Force float32
|
| 726 |
+
freqs = (inv_freq_expanded.float() @
|
| 727 |
+
position_ids_expanded.float()).transpose(1, 2)
|
| 728 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 729 |
+
cos = emb.cos() * self.attention_scaling
|
| 730 |
+
sin = emb.sin() * self.attention_scaling
|
| 731 |
+
|
| 732 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 733 |
+
|
| 734 |
+
|
| 735 |
+
@auto_docstring
|
| 736 |
+
class SDARModel(SDARPreTrainedModel):
|
| 737 |
+
def __init__(self, config: SDARConfig):
|
| 738 |
+
super().__init__(config)
|
| 739 |
+
self.padding_idx = config.pad_token_id
|
| 740 |
+
self.vocab_size = config.vocab_size
|
| 741 |
+
|
| 742 |
+
self.embed_tokens = nn.Embedding(
|
| 743 |
+
config.vocab_size, config.hidden_size, self.padding_idx)
|
| 744 |
+
self.layers = nn.ModuleList(
|
| 745 |
+
[SDARDecoderLayer(config, layer_idx)
|
| 746 |
+
for layer_idx in range(config.num_hidden_layers)]
|
| 747 |
+
)
|
| 748 |
+
self.norm = SDARRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 749 |
+
self.rotary_emb = SDARRotaryEmbedding(config=config)
|
| 750 |
+
self.gradient_checkpointing = False
|
| 751 |
+
|
| 752 |
+
# Initialize weights and apply final processing
|
| 753 |
+
self.post_init()
|
| 754 |
+
|
| 755 |
+
def get_input_embeddings(self):
|
| 756 |
+
return self.embed_tokens
|
| 757 |
+
|
| 758 |
+
def set_input_embeddings(self, value):
|
| 759 |
+
self.embed_tokens = value
|
| 760 |
+
|
| 761 |
+
@can_return_tuple
|
| 762 |
+
@auto_docstring
|
| 763 |
+
def forward(
|
| 764 |
+
self,
|
| 765 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 766 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 767 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 768 |
+
past_key_values: Optional[Cache] = None,
|
| 769 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 770 |
+
use_cache: Optional[bool] = None,
|
| 771 |
+
store_kv: Optional[bool] = None,
|
| 772 |
+
output_attentions: Optional[bool] = None,
|
| 773 |
+
output_hidden_states: Optional[bool] = None,
|
| 774 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 775 |
+
**flash_attn_kwargs: Unpack[FlashAttentionKwargs],
|
| 776 |
+
) -> BaseModelOutputWithPast:
|
| 777 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 778 |
+
output_hidden_states = (
|
| 779 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 780 |
+
)
|
| 781 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 782 |
+
|
| 783 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 784 |
+
raise ValueError(
|
| 785 |
+
"You must specify exactly one of input_ids or inputs_embeds")
|
| 786 |
+
|
| 787 |
+
if self.gradient_checkpointing and self.training and use_cache:
|
| 788 |
+
logger.warning_once(
|
| 789 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
|
| 790 |
+
)
|
| 791 |
+
use_cache = False
|
| 792 |
+
|
| 793 |
+
# TODO (joao): remove this exception in v4.56 -- it exists for users that try to pass a legacy cache
|
| 794 |
+
if not isinstance(past_key_values, (type(None), Cache)):
|
| 795 |
+
raise ValueError(
|
| 796 |
+
"The `past_key_values` should be either a `Cache` object or `None`.")
|
| 797 |
+
|
| 798 |
+
if inputs_embeds is None:
|
| 799 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 800 |
+
|
| 801 |
+
if use_cache and past_key_values is None:
|
| 802 |
+
past_key_values = DynamicCache()
|
| 803 |
+
|
| 804 |
+
if cache_position is None:
|
| 805 |
+
past_seen_tokens = past_key_values.get_seq_length(
|
| 806 |
+
) if past_key_values is not None else 0
|
| 807 |
+
cache_position = torch.arange(
|
| 808 |
+
past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
|
| 809 |
+
)
|
| 810 |
+
|
| 811 |
+
if position_ids is None:
|
| 812 |
+
position_ids = cache_position.unsqueeze(0)
|
| 813 |
+
|
| 814 |
+
# causal_mask = self._update_causal_mask(
|
| 815 |
+
# attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
|
| 816 |
+
# )
|
| 817 |
+
|
| 818 |
+
hidden_states = inputs_embeds
|
| 819 |
+
|
| 820 |
+
# create position embeddings to be shared across the decoder layers
|
| 821 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 822 |
+
|
| 823 |
+
# decoder layers
|
| 824 |
+
all_hidden_states = () if output_hidden_states else None
|
| 825 |
+
all_self_attns = () if output_attentions else None
|
| 826 |
+
|
| 827 |
+
for decoder_layer in self.layers[: self.config.num_hidden_layers]:
|
| 828 |
+
if output_hidden_states:
|
| 829 |
+
all_hidden_states += (hidden_states,)
|
| 830 |
+
|
| 831 |
+
layer_outputs = decoder_layer(
|
| 832 |
+
hidden_states,
|
| 833 |
+
attention_mask=attention_mask,
|
| 834 |
+
position_ids=position_ids,
|
| 835 |
+
past_key_value=past_key_values,
|
| 836 |
+
output_attentions=output_attentions,
|
| 837 |
+
use_cache=use_cache,
|
| 838 |
+
store_kv=store_kv,
|
| 839 |
+
cache_position=cache_position,
|
| 840 |
+
position_embeddings=position_embeddings,
|
| 841 |
+
**flash_attn_kwargs,
|
| 842 |
+
)
|
| 843 |
+
|
| 844 |
+
hidden_states = layer_outputs[0]
|
| 845 |
+
|
| 846 |
+
if output_attentions:
|
| 847 |
+
all_self_attns += (layer_outputs[1],)
|
| 848 |
+
|
| 849 |
+
hidden_states = self.norm(hidden_states)
|
| 850 |
+
|
| 851 |
+
# add hidden states from the last decoder layer
|
| 852 |
+
if output_hidden_states:
|
| 853 |
+
all_hidden_states += (hidden_states,)
|
| 854 |
+
|
| 855 |
+
return BaseModelOutputWithPast(
|
| 856 |
+
last_hidden_state=hidden_states,
|
| 857 |
+
past_key_values=past_key_values if use_cache else None,
|
| 858 |
+
hidden_states=all_hidden_states,
|
| 859 |
+
attentions=all_self_attns,
|
| 860 |
+
)
|
| 861 |
+
|
| 862 |
+
def _update_causal_mask(
|
| 863 |
+
self,
|
| 864 |
+
attention_mask: Union[torch.Tensor, "BlockMask"],
|
| 865 |
+
input_tensor: torch.Tensor,
|
| 866 |
+
cache_position: torch.Tensor,
|
| 867 |
+
past_key_values: Cache,
|
| 868 |
+
output_attentions: bool = False,
|
| 869 |
+
):
|
| 870 |
+
if self.config._attn_implementation == "flash_attention_2":
|
| 871 |
+
if attention_mask is not None and past_key_values is not None:
|
| 872 |
+
is_padding_right = attention_mask[:, -
|
| 873 |
+
1].sum().item() != input_tensor.size()[0]
|
| 874 |
+
if is_padding_right:
|
| 875 |
+
raise ValueError(
|
| 876 |
+
"You are attempting to perform batched generation with padding_side='right'"
|
| 877 |
+
" this may lead to unexpected behaviour for Flash Attention version of Qwen3. Make sure to "
|
| 878 |
+
" call `tokenizer.padding_side = 'left'` before tokenizing the input. "
|
| 879 |
+
)
|
| 880 |
+
if attention_mask is not None and 0.0 in attention_mask:
|
| 881 |
+
return attention_mask
|
| 882 |
+
return None
|
| 883 |
+
if self.config._attn_implementation == "flex_attention":
|
| 884 |
+
if isinstance(attention_mask, torch.Tensor):
|
| 885 |
+
seq_len_q, seq_len_kv = attention_mask.shape
|
| 886 |
+
assert seq_len_q == seq_len_kv, f"got {attention_mask.shape=}"
|
| 887 |
+
attention_mask = create_block_mask(
|
| 888 |
+
# 2d bool tensor, shape: [2*seqlen, 2*seqlen]
|
| 889 |
+
lambda b, h, q_idx, kv_idx: attention_mask[q_idx, kv_idx],
|
| 890 |
+
B=None, H=None, Q_LEN=seq_len_q, KV_LEN=seq_len_kv,
|
| 891 |
+
)
|
| 892 |
+
else:
|
| 893 |
+
# Here we pass in flex mask computed externally
|
| 894 |
+
assert isinstance(attention_mask, BlockMask)
|
| 895 |
+
return attention_mask
|
| 896 |
+
|
| 897 |
+
# For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
|
| 898 |
+
# order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
|
| 899 |
+
# to infer the attention mask.
|
| 900 |
+
past_seen_tokens = past_key_values.get_seq_length(
|
| 901 |
+
) if past_key_values is not None else 0
|
| 902 |
+
using_static_cache = isinstance(past_key_values, StaticCache)
|
| 903 |
+
using_sliding_window_cache = isinstance(
|
| 904 |
+
past_key_values, SlidingWindowCache)
|
| 905 |
+
|
| 906 |
+
# When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
|
| 907 |
+
if (
|
| 908 |
+
self.config._attn_implementation == "sdpa"
|
| 909 |
+
and not (using_static_cache or using_sliding_window_cache)
|
| 910 |
+
and not output_attentions
|
| 911 |
+
):
|
| 912 |
+
if AttentionMaskConverter._ignore_causal_mask_sdpa(
|
| 913 |
+
attention_mask,
|
| 914 |
+
inputs_embeds=input_tensor,
|
| 915 |
+
past_key_values_length=past_seen_tokens,
|
| 916 |
+
sliding_window=self.config.sliding_window,
|
| 917 |
+
is_training=self.training,
|
| 918 |
+
):
|
| 919 |
+
return None
|
| 920 |
+
|
| 921 |
+
dtype = input_tensor.dtype
|
| 922 |
+
min_dtype = torch.finfo(dtype).min
|
| 923 |
+
sequence_length = input_tensor.shape[1]
|
| 924 |
+
# SlidingWindowCache or StaticCache
|
| 925 |
+
if using_sliding_window_cache or using_static_cache:
|
| 926 |
+
target_length = past_key_values.get_max_cache_shape()
|
| 927 |
+
# DynamicCache or no cache
|
| 928 |
+
else:
|
| 929 |
+
target_length = (
|
| 930 |
+
attention_mask.shape[-1]
|
| 931 |
+
if isinstance(attention_mask, torch.Tensor)
|
| 932 |
+
else past_seen_tokens + sequence_length + 1
|
| 933 |
+
)
|
| 934 |
+
|
| 935 |
+
# In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
|
| 936 |
+
causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
|
| 937 |
+
attention_mask,
|
| 938 |
+
sequence_length=sequence_length,
|
| 939 |
+
target_length=target_length,
|
| 940 |
+
dtype=dtype,
|
| 941 |
+
cache_position=cache_position,
|
| 942 |
+
batch_size=input_tensor.shape[0],
|
| 943 |
+
config=self.config,
|
| 944 |
+
past_key_values=past_key_values,
|
| 945 |
+
)
|
| 946 |
+
|
| 947 |
+
if (
|
| 948 |
+
self.config._attn_implementation == "sdpa"
|
| 949 |
+
and attention_mask is not None
|
| 950 |
+
and attention_mask.device.type in ["cuda", "xpu", "npu"]
|
| 951 |
+
and not output_attentions
|
| 952 |
+
):
|
| 953 |
+
# Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
|
| 954 |
+
# using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
|
| 955 |
+
# Details: https://github.com/pytorch/pytorch/issues/110213
|
| 956 |
+
causal_mask = AttentionMaskConverter._unmask_unattended(
|
| 957 |
+
causal_mask, min_dtype)
|
| 958 |
+
|
| 959 |
+
return causal_mask
|
| 960 |
+
|
| 961 |
+
@staticmethod
|
| 962 |
+
def _prepare_4d_causal_attention_mask_with_cache_position(
|
| 963 |
+
attention_mask: torch.Tensor,
|
| 964 |
+
sequence_length: int,
|
| 965 |
+
target_length: int,
|
| 966 |
+
dtype: torch.dtype,
|
| 967 |
+
cache_position: torch.Tensor,
|
| 968 |
+
batch_size: int,
|
| 969 |
+
config: SDARConfig,
|
| 970 |
+
past_key_values: Cache,
|
| 971 |
+
):
|
| 972 |
+
"""
|
| 973 |
+
Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
|
| 974 |
+
`(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
|
| 975 |
+
|
| 976 |
+
Args:
|
| 977 |
+
attention_mask (`torch.Tensor`):
|
| 978 |
+
A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape `(batch_size, 1, query_length, key_value_length)`.
|
| 979 |
+
sequence_length (`int`):
|
| 980 |
+
The sequence length being processed.
|
| 981 |
+
target_length (`int`):
|
| 982 |
+
The target length: when generating with static cache, the mask should be as long as the static cache, to account for the 0 padding, the part of the cache that is not filled yet.
|
| 983 |
+
dtype (`torch.dtype`):
|
| 984 |
+
The dtype to use for the 4D attention mask.
|
| 985 |
+
cache_position (`torch.Tensor`):
|
| 986 |
+
Indices depicting the position of the input sequence tokens in the sequence.
|
| 987 |
+
batch_size (`torch.Tensor`):
|
| 988 |
+
Batch size.
|
| 989 |
+
config (`SDARConfig`):
|
| 990 |
+
The model's configuration class
|
| 991 |
+
past_key_values (`Cache`):
|
| 992 |
+
The cache class that is being used currently to generate
|
| 993 |
+
"""
|
| 994 |
+
if attention_mask is not None and attention_mask.dim() == 4:
|
| 995 |
+
# In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
|
| 996 |
+
causal_mask = attention_mask
|
| 997 |
+
else:
|
| 998 |
+
min_dtype = torch.finfo(dtype).min
|
| 999 |
+
causal_mask = torch.full(
|
| 1000 |
+
(sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=cache_position.device
|
| 1001 |
+
)
|
| 1002 |
+
diagonal_attend_mask = torch.arange(target_length, device=cache_position.device) > cache_position.reshape(
|
| 1003 |
+
-1, 1
|
| 1004 |
+
)
|
| 1005 |
+
text_config = config.get_text_config()
|
| 1006 |
+
if getattr(text_config, "use_sliding_window", True) and text_config.sliding_window is not None:
|
| 1007 |
+
# if we have sliding window, we should not attend to tokens beyond sliding window length, so we mask them out also
|
| 1008 |
+
# the check is needed to verify is current checkpoint was trained with sliding window or not
|
| 1009 |
+
if not isinstance(past_key_values, SlidingWindowCache) or sequence_length > target_length:
|
| 1010 |
+
sliding_attend_mask = torch.arange(target_length, device=cache_position.device) <= (
|
| 1011 |
+
cache_position.reshape(-1, 1) -
|
| 1012 |
+
text_config.sliding_window
|
| 1013 |
+
)
|
| 1014 |
+
diagonal_attend_mask.bitwise_or_(sliding_attend_mask)
|
| 1015 |
+
causal_mask *= diagonal_attend_mask
|
| 1016 |
+
causal_mask = causal_mask[None, None,
|
| 1017 |
+
:, :].expand(batch_size, 1, -1, -1)
|
| 1018 |
+
if attention_mask is not None:
|
| 1019 |
+
causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
|
| 1020 |
+
if attention_mask.shape[-1] > target_length:
|
| 1021 |
+
attention_mask = attention_mask[:, :target_length]
|
| 1022 |
+
mask_length = attention_mask.shape[-1]
|
| 1023 |
+
padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :].to(
|
| 1024 |
+
causal_mask.device
|
| 1025 |
+
)
|
| 1026 |
+
padding_mask = padding_mask == 0
|
| 1027 |
+
causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
|
| 1028 |
+
padding_mask, min_dtype
|
| 1029 |
+
)
|
| 1030 |
+
return causal_mask
|
| 1031 |
+
|
| 1032 |
+
|
| 1033 |
+
class KwargsForCausalLM(FlashAttentionKwargs, LossKwargs):
|
| 1034 |
+
...
|
| 1035 |
+
|
| 1036 |
+
|
| 1037 |
+
@auto_docstring
|
| 1038 |
+
class SDARForCausalLM(SDARPreTrainedModel, GenerationMixin):
|
| 1039 |
+
_tied_weights_keys = ["lm_head.weight"]
|
| 1040 |
+
_tp_plan = {"lm_head": "colwise_rep"}
|
| 1041 |
+
_pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
|
| 1042 |
+
|
| 1043 |
+
def __init__(self, config):
|
| 1044 |
+
super().__init__(config)
|
| 1045 |
+
self.model = SDARModel(config)
|
| 1046 |
+
self.vocab_size = config.vocab_size
|
| 1047 |
+
self.lm_head = nn.Linear(
|
| 1048 |
+
config.hidden_size, config.vocab_size, bias=False)
|
| 1049 |
+
|
| 1050 |
+
# Initialize weights and apply final processing
|
| 1051 |
+
self.post_init()
|
| 1052 |
+
|
| 1053 |
+
def get_input_embeddings(self):
|
| 1054 |
+
return self.model.embed_tokens
|
| 1055 |
+
|
| 1056 |
+
def set_input_embeddings(self, value):
|
| 1057 |
+
self.model.embed_tokens = value
|
| 1058 |
+
|
| 1059 |
+
def get_output_embeddings(self):
|
| 1060 |
+
return self.lm_head
|
| 1061 |
+
|
| 1062 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1063 |
+
self.lm_head = new_embeddings
|
| 1064 |
+
|
| 1065 |
+
def set_decoder(self, decoder):
|
| 1066 |
+
self.model = decoder
|
| 1067 |
+
|
| 1068 |
+
def get_decoder(self):
|
| 1069 |
+
return self.model
|
| 1070 |
+
|
| 1071 |
+
def prepare_for_bd_training(self, inputs_ids, position_ids, prompt_mask):
|
| 1072 |
+
bsz, seq_len = inputs_ids.shape
|
| 1073 |
+
num_tokens = calculate_token_nums(position_ids) # List[torch.Tensor]
|
| 1074 |
+
noisy_inputs_ids, logits_to_keep_half, p_mask = forward_add_noise_packed(
|
| 1075 |
+
inputs_ids=inputs_ids,
|
| 1076 |
+
num_tokens_list=num_tokens,
|
| 1077 |
+
prompt_mask=prompt_mask,
|
| 1078 |
+
mask_id=self.config.mask_token_id,
|
| 1079 |
+
eob_token_id=getattr(self.config, "eob_token_id", None),
|
| 1080 |
+
)
|
| 1081 |
+
router_noisy_part_list = []
|
| 1082 |
+
for i in range(bsz):
|
| 1083 |
+
cur_router_noisy_part = (torch.arange(num_tokens[i].shape[0] *2) % 2 == 0).to(inputs_ids.device)
|
| 1084 |
+
cur_router_noisy_part = cur_router_noisy_part.repeat_interleave(num_tokens[i].repeat_interleave(2))
|
| 1085 |
+
router_noisy_part_list.append(cur_router_noisy_part)
|
| 1086 |
+
router_noisy_part = torch.stack(router_noisy_part_list, dim=0)
|
| 1087 |
+
|
| 1088 |
+
# concated inputs_ids: (bzs, seq_len x 2)
|
| 1089 |
+
concat_inputs_ids = inputs_ids.repeat(1, 2)
|
| 1090 |
+
# concated logits_to_keep: (bsz, seq_len x 2)
|
| 1091 |
+
logits_to_keep = torch.zeros(
|
| 1092 |
+
bsz, 2 * seq_len, dtype=torch.bool, device=inputs_ids.device)
|
| 1093 |
+
# concated position_ids: (bsz, seq_len x 2)
|
| 1094 |
+
concat_position_ids = torch.zeros(
|
| 1095 |
+
bsz, 2 * seq_len, dtype=position_ids.dtype, device=position_ids.device)
|
| 1096 |
+
for i in range(bsz):
|
| 1097 |
+
concat_inputs_ids[i][router_noisy_part[i]] = noisy_inputs_ids[i]
|
| 1098 |
+
concat_inputs_ids[i][~router_noisy_part[i]] = inputs_ids[i]
|
| 1099 |
+
|
| 1100 |
+
logits_to_keep[i][router_noisy_part[i]] = logits_to_keep_half[i]
|
| 1101 |
+
|
| 1102 |
+
concat_position_ids[i][router_noisy_part[i]] = position_ids[i]
|
| 1103 |
+
concat_position_ids[i][~router_noisy_part[i]] = position_ids[i]
|
| 1104 |
+
|
| 1105 |
+
# create flex_attention mask
|
| 1106 |
+
if getattr(self.config, "dynamic_blocks", False) and getattr(self.config, "eob_token_id", None) is not None:
|
| 1107 |
+
# Dynamic blocks based on EOB tokens
|
| 1108 |
+
block_lengths_list = calculate_block_nums_from_eob(inputs_ids, num_tokens, self.config.eob_token_id)
|
| 1109 |
+
attention_mask = block_attn_mask_dynamic(block_lengths_list, inputs_ids.device)
|
| 1110 |
+
else:
|
| 1111 |
+
# Fixed blocks
|
| 1112 |
+
attention_mask = block_attn_mask(num_tokens, self.config.block_size, inputs_ids.device)
|
| 1113 |
+
|
| 1114 |
+
flex_attention_mask_3d = create_block_mask(
|
| 1115 |
+
lambda b, h, q_idx, kv_idx: attention_mask[b, q_idx, kv_idx],
|
| 1116 |
+
B=attention_mask.size(0), H=None,
|
| 1117 |
+
Q_LEN=attention_mask.size(1), KV_LEN=attention_mask.size(2),
|
| 1118 |
+
)
|
| 1119 |
+
|
| 1120 |
+
return concat_inputs_ids, concat_position_ids, flex_attention_mask_3d, logits_to_keep_half, logits_to_keep, p_mask
|
| 1121 |
+
|
| 1122 |
+
@can_return_tuple
|
| 1123 |
+
@auto_docstring
|
| 1124 |
+
def forward(
|
| 1125 |
+
self,
|
| 1126 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1127 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1128 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1129 |
+
past_key_values: Optional[Cache] = None,
|
| 1130 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1131 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1132 |
+
use_cache: Optional[bool] = None,
|
| 1133 |
+
output_attentions: Optional[bool] = None,
|
| 1134 |
+
output_hidden_states: Optional[bool] = None,
|
| 1135 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 1136 |
+
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 1137 |
+
**kwargs: Unpack[KwargsForCausalLM],
|
| 1138 |
+
) -> CausalLMOutputWithPast:
|
| 1139 |
+
r"""
|
| 1140 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1141 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 1142 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 1143 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 1144 |
+
|
| 1145 |
+
Example:
|
| 1146 |
+
|
| 1147 |
+
```python
|
| 1148 |
+
>>> from transformers import AutoTokenizer, SDARForCausalLM
|
| 1149 |
+
|
| 1150 |
+
>>> model = SDARForCausalLM.from_pretrained("DiffuOpen/SDAR-1.7B-Chat")
|
| 1151 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("DiffuOpen/SDAR-1.7B-Chat")
|
| 1152 |
+
|
| 1153 |
+
>>> prompt = "Hey, are you conscious? Can you talk to me?"
|
| 1154 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
| 1155 |
+
|
| 1156 |
+
>>> # Generate
|
| 1157 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
| 1158 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 1159 |
+
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
|
| 1160 |
+
```"""
|
| 1161 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1162 |
+
output_hidden_states = (
|
| 1163 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1164 |
+
)
|
| 1165 |
+
if self.training:
|
| 1166 |
+
assert inputs_embeds is None, "only support input_ids during training"
|
| 1167 |
+
prompt_mask = (labels == -100) if labels is not None else None
|
| 1168 |
+
position_ids = modify_padded_position_ids_2d(position_ids)
|
| 1169 |
+
concat_inputs_ids, concat_position_ids, flex_attention_mask_3d, logits_to_keep_half, logits_to_keep, p_mask = self.prepare_for_bd_training(input_ids, position_ids, prompt_mask)
|
| 1170 |
+
outputs = self.model(
|
| 1171 |
+
input_ids=concat_inputs_ids,
|
| 1172 |
+
attention_mask=flex_attention_mask_3d,
|
| 1173 |
+
position_ids=concat_position_ids,
|
| 1174 |
+
output_attentions=output_attentions,
|
| 1175 |
+
output_hidden_states=output_hidden_states,
|
| 1176 |
+
return_dict=True,
|
| 1177 |
+
cache_position=cache_position,
|
| 1178 |
+
**kwargs,
|
| 1179 |
+
)
|
| 1180 |
+
hidden_states = outputs.last_hidden_state
|
| 1181 |
+
hidden_states = hidden_states[logits_to_keep].contiguous()
|
| 1182 |
+
assert labels is not None, "Labels must be provided for training."
|
| 1183 |
+
labels = labels[logits_to_keep_half].contiguous()
|
| 1184 |
+
loss_fct = FusedLinearDiffusionCrossEntropyLoss(reduction='sum')
|
| 1185 |
+
loss = loss_fct( # it will return (sum_loss, unreduced_loss)
|
| 1186 |
+
# conduct `view(-1, V)` inside the function
|
| 1187 |
+
x=hidden_states,
|
| 1188 |
+
target=labels,
|
| 1189 |
+
weight=self.lm_head.weight,
|
| 1190 |
+
bias=self.lm_head.bias,
|
| 1191 |
+
p_mask=p_mask,
|
| 1192 |
+
eob_token_id=getattr(self.config, "eob_token_id", None),
|
| 1193 |
+
eob_weight=getattr(self.config, "eob_weight", 1.0),
|
| 1194 |
+
)
|
| 1195 |
+
loss = loss / labels.numel()
|
| 1196 |
+
logits = None
|
| 1197 |
+
else:
|
| 1198 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 1199 |
+
outputs: BaseModelOutputWithPast = self.model(
|
| 1200 |
+
input_ids=input_ids,
|
| 1201 |
+
attention_mask=attention_mask,
|
| 1202 |
+
position_ids=position_ids,
|
| 1203 |
+
past_key_values=past_key_values,
|
| 1204 |
+
inputs_embeds=inputs_embeds,
|
| 1205 |
+
use_cache=use_cache,
|
| 1206 |
+
output_attentions=output_attentions,
|
| 1207 |
+
output_hidden_states=output_hidden_states,
|
| 1208 |
+
cache_position=cache_position,
|
| 1209 |
+
**kwargs,
|
| 1210 |
+
)
|
| 1211 |
+
|
| 1212 |
+
hidden_states = outputs.last_hidden_state
|
| 1213 |
+
# Only compute necessary logits, and do not upcast them to float if we are not computing the loss
|
| 1214 |
+
slice_indices = slice(-logits_to_keep,
|
| 1215 |
+
None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 1216 |
+
hidden_states = hidden_states[:, slice_indices, :].contiguous()
|
| 1217 |
+
fuse_linear_and_cross_entropy = self.config.fuse_cross_entropy and self.training
|
| 1218 |
+
if fuse_linear_and_cross_entropy:
|
| 1219 |
+
# When using fused_linear_ce_loss, we do not compute the whole logits on HBM
|
| 1220 |
+
logits = None
|
| 1221 |
+
else:
|
| 1222 |
+
logits = self.lm_head(hidden_states)
|
| 1223 |
+
|
| 1224 |
+
loss = None
|
| 1225 |
+
if labels is not None:
|
| 1226 |
+
# FusedLinearCrossEntropyLoss will be implemented by monkey patch when training
|
| 1227 |
+
# We don't use it when inferencing
|
| 1228 |
+
loss_fct = nn.CrossEntropyLoss() # nn.CE
|
| 1229 |
+
loss = loss_fct(
|
| 1230 |
+
logits.view(-1, self.config.vocab_size), labels.view(-1))
|
| 1231 |
+
|
| 1232 |
+
return CausalLMOutputWithPast(
|
| 1233 |
+
loss=loss,
|
| 1234 |
+
logits=logits,
|
| 1235 |
+
past_key_values=outputs.past_key_values,
|
| 1236 |
+
hidden_states=outputs.hidden_states,
|
| 1237 |
+
attentions=outputs.attentions,
|
| 1238 |
+
)
|
| 1239 |
+
|
| 1240 |
+
|
| 1241 |
+
__all__ = [
|
| 1242 |
+
"SDARForCausalLM",
|
| 1243 |
+
"SDARModel",
|
| 1244 |
+
"SDARPreTrainedModel",
|
| 1245 |
+
]
|
rng_state_0.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:25c62d345be8e040c196fb33f0e649d52b41ea74e0f2ba1fb163bd3eb2abe1a7
|
| 3 |
+
size 16133
|
rng_state_1.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9f842350c63e633f32f33db4a1fcd5da03a73c43d86665c6e935919c09efda43
|
| 3 |
+
size 16133
|
rng_state_2.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b3c6b1564d12078d05ae00b585e01af634598a41e7a5166a489bf7e00024943d
|
| 3 |
+
size 16133
|
rng_state_3.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1a6da4163f04f24e920a83f2647a1ac25e4ef5b4ee0c8cbe5e94570a84ffb029
|
| 3 |
+
size 16133
|
rng_state_4.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7f404a929daa54e7845502018f60a891cdbda19558e0b8d18a6452d57c61a8e0
|
| 3 |
+
size 16133
|
rng_state_5.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cbc0b9bb52448a6f9dedccf684c93906a535f1d5ba3b9851bfd098d15f291df9
|
| 3 |
+
size 16133
|
rng_state_6.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:99b132e59a3199b46987dc184d1675f4aef42e3dcb2d13bbd5d888152aa0afb4
|
| 3 |
+
size 16133
|
scheduler.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f14e5100356e29b1d39819aba28314a603c8339a038828cf64e69f89bd67e7a5
|
| 3 |
+
size 1465
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"additional_special_tokens": [
|
| 3 |
+
"<|im_start|>",
|
| 4 |
+
"<|im_end|>",
|
| 5 |
+
"<|object_ref_start|>",
|
| 6 |
+
"<|object_ref_end|>",
|
| 7 |
+
"<|box_start|>",
|
| 8 |
+
"<|box_end|>",
|
| 9 |
+
"<|quad_start|>",
|
| 10 |
+
"<|quad_end|>",
|
| 11 |
+
"<|vision_start|>",
|
| 12 |
+
"<|vision_end|>",
|
| 13 |
+
"<|vision_pad|>",
|
| 14 |
+
"<|image_pad|>",
|
| 15 |
+
"<|video_pad|>",
|
| 16 |
+
"<|MASK|>",
|
| 17 |
+
"<EOB>"
|
| 18 |
+
],
|
| 19 |
+
"eos_token": {
|
| 20 |
+
"content": "<|im_end|>",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false
|
| 25 |
+
},
|
| 26 |
+
"mask_token": {
|
| 27 |
+
"content": "<|MASK|>",
|
| 28 |
+
"lstrip": false,
|
| 29 |
+
"normalized": false,
|
| 30 |
+
"rstrip": false,
|
| 31 |
+
"single_word": false
|
| 32 |
+
},
|
| 33 |
+
"pad_token": {
|
| 34 |
+
"content": "<|endoftext|>",
|
| 35 |
+
"lstrip": false,
|
| 36 |
+
"normalized": false,
|
| 37 |
+
"rstrip": false,
|
| 38 |
+
"single_word": false
|
| 39 |
+
}
|
| 40 |
+
}
|
tokenization_qwen2.py
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 The Qwen team, Alibaba Group and The HuggingFace Inc. team. All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
"""Tokenization classes for Qwen2."""
|
| 16 |
+
|
| 17 |
+
import json
|
| 18 |
+
import os
|
| 19 |
+
import unicodedata
|
| 20 |
+
from functools import lru_cache
|
| 21 |
+
from typing import Optional, Tuple
|
| 22 |
+
|
| 23 |
+
import regex as re
|
| 24 |
+
|
| 25 |
+
from transformers.tokenization_utils import AddedToken, PreTrainedTokenizer
|
| 26 |
+
from transformers.utils import logging
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
logger = logging.get_logger(__name__)
|
| 30 |
+
|
| 31 |
+
VOCAB_FILES_NAMES = {
|
| 32 |
+
"vocab_file": "vocab.json",
|
| 33 |
+
"merges_file": "merges.txt",
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
MAX_MODEL_INPUT_SIZES = {"qwen/qwen-tokenizer": 32768}
|
| 38 |
+
|
| 39 |
+
PRETOKENIZE_REGEX = r"""(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"""
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
@lru_cache()
|
| 43 |
+
# Copied from transformers.models.gpt2.tokenization_gpt2.bytes_to_unicode
|
| 44 |
+
def bytes_to_unicode():
|
| 45 |
+
"""
|
| 46 |
+
Returns list of utf-8 byte and a mapping to unicode strings. We specifically avoids mapping to whitespace/control
|
| 47 |
+
characters the bpe code barfs on.
|
| 48 |
+
|
| 49 |
+
The reversible bpe codes work on unicode strings. This means you need a large # of unicode characters in your vocab
|
| 50 |
+
if you want to avoid UNKs. When you're at something like a 10B token dataset you end up needing around 5K for
|
| 51 |
+
decent coverage. This is a significant percentage of your normal, say, 32K bpe vocab. To avoid that, we want lookup
|
| 52 |
+
tables between utf-8 bytes and unicode strings.
|
| 53 |
+
"""
|
| 54 |
+
bs = (
|
| 55 |
+
list(range(ord("!"), ord("~") + 1)) + list(range(ord("¡"), ord("¬") + 1)) + list(range(ord("®"), ord("ÿ") + 1))
|
| 56 |
+
)
|
| 57 |
+
cs = bs[:]
|
| 58 |
+
n = 0
|
| 59 |
+
for b in range(2**8):
|
| 60 |
+
if b not in bs:
|
| 61 |
+
bs.append(b)
|
| 62 |
+
cs.append(2**8 + n)
|
| 63 |
+
n += 1
|
| 64 |
+
cs = [chr(n) for n in cs]
|
| 65 |
+
return dict(zip(bs, cs))
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# Copied from transformers.models.gpt2.tokenization_gpt2.get_pairs
|
| 69 |
+
def get_pairs(word):
|
| 70 |
+
"""
|
| 71 |
+
Return set of symbol pairs in a word.
|
| 72 |
+
|
| 73 |
+
Word is represented as tuple of symbols (symbols being variable-length strings).
|
| 74 |
+
"""
|
| 75 |
+
pairs = set()
|
| 76 |
+
prev_char = word[0]
|
| 77 |
+
for char in word[1:]:
|
| 78 |
+
pairs.add((prev_char, char))
|
| 79 |
+
prev_char = char
|
| 80 |
+
return pairs
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class Qwen2Tokenizer(PreTrainedTokenizer):
|
| 84 |
+
"""
|
| 85 |
+
Construct a Qwen2 tokenizer. Based on byte-level Byte-Pair-Encoding.
|
| 86 |
+
|
| 87 |
+
Same with GPT2Tokenizer, this tokenizer has been trained to treat spaces like parts of the tokens so a word will
|
| 88 |
+
be encoded differently whether it is at the beginning of the sentence (without space) or not:
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
>>> from transformers import Qwen2Tokenizer
|
| 92 |
+
|
| 93 |
+
>>> tokenizer = Qwen2Tokenizer.from_pretrained("Qwen/Qwen-tokenizer")
|
| 94 |
+
>>> tokenizer("Hello world")["input_ids"]
|
| 95 |
+
[9707, 1879]
|
| 96 |
+
|
| 97 |
+
>>> tokenizer(" Hello world")["input_ids"]
|
| 98 |
+
[21927, 1879]
|
| 99 |
+
```
|
| 100 |
+
This is expected.
|
| 101 |
+
|
| 102 |
+
You should not use GPT2Tokenizer instead, because of the different pretokenization rules.
|
| 103 |
+
|
| 104 |
+
This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to
|
| 105 |
+
this superclass for more information regarding those methods.
|
| 106 |
+
|
| 107 |
+
Args:
|
| 108 |
+
vocab_file (`str`):
|
| 109 |
+
Path to the vocabulary file.
|
| 110 |
+
merges_file (`str`):
|
| 111 |
+
Path to the merges file.
|
| 112 |
+
errors (`str`, *optional*, defaults to `"replace"`):
|
| 113 |
+
Paradigm to follow when decoding bytes to UTF-8. See
|
| 114 |
+
[bytes.decode](https://docs.python.org/3/library/stdtypes.html#bytes.decode) for more information.
|
| 115 |
+
unk_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
|
| 116 |
+
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
|
| 117 |
+
token instead.
|
| 118 |
+
bos_token (`str`, *optional*):
|
| 119 |
+
The beginning of sequence token. Not applicable for this tokenizer.
|
| 120 |
+
eos_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
|
| 121 |
+
The end of sequence token.
|
| 122 |
+
pad_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
|
| 123 |
+
The token used for padding, for example when batching sequences of different lengths.
|
| 124 |
+
clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`):
|
| 125 |
+
Whether or not the model should cleanup the spaces that were added when splitting the input text during the
|
| 126 |
+
tokenization process. Not applicable to this tokenizer, since tokenization does not add spaces.
|
| 127 |
+
split_special_tokens (`bool`, *optional*, defaults to `False`):
|
| 128 |
+
Whether or not the special tokens should be split during the tokenization process. The default behavior is
|
| 129 |
+
to not split special tokens. This means that if `<|endoftext|>` is the `eos_token`, then `tokenizer.tokenize("<|endoftext|>") =
|
| 130 |
+
['<|endoftext|>`]. Otherwise, if `split_special_tokens=True`, then `tokenizer.tokenize("<|endoftext|>")` will be give `['<',
|
| 131 |
+
'|', 'endo', 'ft', 'ext', '|', '>']`. This argument is only supported for `slow` tokenizers for the moment.
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
vocab_files_names = VOCAB_FILES_NAMES
|
| 135 |
+
model_input_names = ["input_ids", "attention_mask"]
|
| 136 |
+
|
| 137 |
+
def __init__(
|
| 138 |
+
self,
|
| 139 |
+
vocab_file,
|
| 140 |
+
merges_file,
|
| 141 |
+
errors="replace",
|
| 142 |
+
unk_token="<|endoftext|>",
|
| 143 |
+
bos_token=None,
|
| 144 |
+
eos_token="<|endoftext|>",
|
| 145 |
+
pad_token="<|endoftext|>",
|
| 146 |
+
clean_up_tokenization_spaces=False,
|
| 147 |
+
split_special_tokens=False,
|
| 148 |
+
**kwargs,
|
| 149 |
+
):
|
| 150 |
+
# Qwen vocab does not contain control tokens; added tokens need to be special
|
| 151 |
+
bos_token = (
|
| 152 |
+
AddedToken(bos_token, lstrip=False, rstrip=False, special=True, normalized=False)
|
| 153 |
+
if isinstance(bos_token, str)
|
| 154 |
+
else bos_token
|
| 155 |
+
)
|
| 156 |
+
eos_token = (
|
| 157 |
+
AddedToken(eos_token, lstrip=False, rstrip=False, special=True, normalized=False)
|
| 158 |
+
if isinstance(eos_token, str)
|
| 159 |
+
else eos_token
|
| 160 |
+
)
|
| 161 |
+
unk_token = (
|
| 162 |
+
AddedToken(unk_token, lstrip=False, rstrip=False, special=True, normalized=False)
|
| 163 |
+
if isinstance(unk_token, str)
|
| 164 |
+
else unk_token
|
| 165 |
+
)
|
| 166 |
+
pad_token = (
|
| 167 |
+
AddedToken(pad_token, lstrip=False, rstrip=False, special=True, normalized=False)
|
| 168 |
+
if isinstance(pad_token, str)
|
| 169 |
+
else pad_token
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
with open(vocab_file, encoding="utf-8") as vocab_handle:
|
| 173 |
+
self.encoder = json.load(vocab_handle)
|
| 174 |
+
self.decoder = {v: k for k, v in self.encoder.items()}
|
| 175 |
+
self.errors = errors # how to handle errors in decoding
|
| 176 |
+
self.byte_encoder = bytes_to_unicode()
|
| 177 |
+
self.byte_decoder = {v: k for k, v in self.byte_encoder.items()}
|
| 178 |
+
bpe_merges = []
|
| 179 |
+
with open(merges_file, encoding="utf-8") as merges_handle:
|
| 180 |
+
for i, line in enumerate(merges_handle):
|
| 181 |
+
line = line.strip()
|
| 182 |
+
if (i == 0 and line.startswith("#version:")) or not line:
|
| 183 |
+
continue
|
| 184 |
+
bpe_merges.append(tuple(line.split()))
|
| 185 |
+
self.bpe_ranks = dict(zip(bpe_merges, range(len(bpe_merges))))
|
| 186 |
+
# NOTE: the cache can grow without bound and will get really large for long running processes
|
| 187 |
+
# (esp. for texts of language that do not use space between word, e.g. Chinese); technically
|
| 188 |
+
# not a memory leak but appears as one.
|
| 189 |
+
# GPT2Tokenizer has the same problem, so let's be consistent.
|
| 190 |
+
self.cache = {}
|
| 191 |
+
|
| 192 |
+
self.pat = re.compile(PRETOKENIZE_REGEX)
|
| 193 |
+
|
| 194 |
+
if kwargs.get("add_prefix_space", False):
|
| 195 |
+
logger.warning_once(
|
| 196 |
+
f"{self.__class__.__name} does not support `add_prefix_space`, setting it to True has no effect."
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
super().__init__(
|
| 200 |
+
errors=errors,
|
| 201 |
+
bos_token=bos_token,
|
| 202 |
+
eos_token=eos_token,
|
| 203 |
+
pad_token=pad_token,
|
| 204 |
+
unk_token=unk_token,
|
| 205 |
+
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
|
| 206 |
+
split_special_tokens=split_special_tokens,
|
| 207 |
+
**kwargs,
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
@property
|
| 211 |
+
def vocab_size(self) -> int:
|
| 212 |
+
return len(self.encoder)
|
| 213 |
+
|
| 214 |
+
# Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer.get_vocab
|
| 215 |
+
def get_vocab(self):
|
| 216 |
+
return dict(self.encoder, **self.added_tokens_encoder)
|
| 217 |
+
|
| 218 |
+
# Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer.bpe
|
| 219 |
+
def bpe(self, token):
|
| 220 |
+
if token in self.cache:
|
| 221 |
+
return self.cache[token]
|
| 222 |
+
word = tuple(token)
|
| 223 |
+
pairs = get_pairs(word)
|
| 224 |
+
|
| 225 |
+
if not pairs:
|
| 226 |
+
return token
|
| 227 |
+
|
| 228 |
+
while True:
|
| 229 |
+
bigram = min(pairs, key=lambda pair: self.bpe_ranks.get(pair, float("inf")))
|
| 230 |
+
if bigram not in self.bpe_ranks:
|
| 231 |
+
break
|
| 232 |
+
first, second = bigram
|
| 233 |
+
new_word = []
|
| 234 |
+
i = 0
|
| 235 |
+
while i < len(word):
|
| 236 |
+
try:
|
| 237 |
+
j = word.index(first, i)
|
| 238 |
+
except ValueError:
|
| 239 |
+
new_word.extend(word[i:])
|
| 240 |
+
break
|
| 241 |
+
else:
|
| 242 |
+
new_word.extend(word[i:j])
|
| 243 |
+
i = j
|
| 244 |
+
|
| 245 |
+
if word[i] == first and i < len(word) - 1 and word[i + 1] == second:
|
| 246 |
+
new_word.append(first + second)
|
| 247 |
+
i += 2
|
| 248 |
+
else:
|
| 249 |
+
new_word.append(word[i])
|
| 250 |
+
i += 1
|
| 251 |
+
new_word = tuple(new_word)
|
| 252 |
+
word = new_word
|
| 253 |
+
if len(word) == 1:
|
| 254 |
+
break
|
| 255 |
+
else:
|
| 256 |
+
pairs = get_pairs(word)
|
| 257 |
+
word = " ".join(word)
|
| 258 |
+
self.cache[token] = word
|
| 259 |
+
return word
|
| 260 |
+
|
| 261 |
+
# Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer._tokenize
|
| 262 |
+
def _tokenize(self, text):
|
| 263 |
+
"""Tokenize a string."""
|
| 264 |
+
bpe_tokens = []
|
| 265 |
+
for token in re.findall(self.pat, text):
|
| 266 |
+
token = "".join(
|
| 267 |
+
self.byte_encoder[b] for b in token.encode("utf-8")
|
| 268 |
+
) # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
|
| 269 |
+
bpe_tokens.extend(bpe_token for bpe_token in self.bpe(token).split(" "))
|
| 270 |
+
return bpe_tokens
|
| 271 |
+
|
| 272 |
+
# Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer._convert_token_to_id
|
| 273 |
+
def _convert_token_to_id(self, token):
|
| 274 |
+
"""Converts a token (str) in an id using the vocab."""
|
| 275 |
+
return self.encoder.get(token, self.encoder.get(self.unk_token))
|
| 276 |
+
|
| 277 |
+
# Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer._convert_id_to_token
|
| 278 |
+
def _convert_id_to_token(self, index):
|
| 279 |
+
"""Converts an index (integer) in a token (str) using the vocab."""
|
| 280 |
+
return self.decoder.get(index)
|
| 281 |
+
|
| 282 |
+
# Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer.convert_tokens_to_string
|
| 283 |
+
def convert_tokens_to_string(self, tokens):
|
| 284 |
+
"""Converts a sequence of tokens (string) in a single string."""
|
| 285 |
+
text = "".join(tokens)
|
| 286 |
+
text = bytearray([self.byte_decoder[c] for c in text]).decode("utf-8", errors=self.errors)
|
| 287 |
+
return text
|
| 288 |
+
|
| 289 |
+
def decode(
|
| 290 |
+
self,
|
| 291 |
+
token_ids,
|
| 292 |
+
skip_special_tokens: bool = False,
|
| 293 |
+
clean_up_tokenization_spaces: Optional[bool] = False,
|
| 294 |
+
spaces_between_special_tokens: bool = False,
|
| 295 |
+
**kwargs,
|
| 296 |
+
) -> str:
|
| 297 |
+
# `spaces_between_special_tokens` defaults to True for _decode in slow tokenizers
|
| 298 |
+
# and cannot be configured elsewhere, but it should default to False for Qwen2Tokenizer
|
| 299 |
+
return super().decode(
|
| 300 |
+
token_ids,
|
| 301 |
+
skip_special_tokens=skip_special_tokens,
|
| 302 |
+
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
|
| 303 |
+
spaces_between_special_tokens=spaces_between_special_tokens,
|
| 304 |
+
**kwargs,
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
# Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer.save_vocabulary
|
| 308 |
+
def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]:
|
| 309 |
+
if not os.path.isdir(save_directory):
|
| 310 |
+
logger.error(f"Vocabulary path ({save_directory}) should be a directory")
|
| 311 |
+
return
|
| 312 |
+
vocab_file = os.path.join(
|
| 313 |
+
save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
|
| 314 |
+
)
|
| 315 |
+
merge_file = os.path.join(
|
| 316 |
+
save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["merges_file"]
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
with open(vocab_file, "w", encoding="utf-8") as f:
|
| 320 |
+
f.write(json.dumps(self.encoder, indent=2, sort_keys=True, ensure_ascii=False) + "\n")
|
| 321 |
+
|
| 322 |
+
index = 0
|
| 323 |
+
with open(merge_file, "w", encoding="utf-8") as writer:
|
| 324 |
+
writer.write("#version: 0.2\n")
|
| 325 |
+
for bpe_tokens, token_index in sorted(self.bpe_ranks.items(), key=lambda kv: kv[1]):
|
| 326 |
+
if index != token_index:
|
| 327 |
+
logger.warning(
|
| 328 |
+
f"Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."
|
| 329 |
+
" Please check that the tokenizer is not corrupted!"
|
| 330 |
+
)
|
| 331 |
+
index = token_index
|
| 332 |
+
writer.write(" ".join(bpe_tokens) + "\n")
|
| 333 |
+
index += 1
|
| 334 |
+
|
| 335 |
+
return vocab_file, merge_file
|
| 336 |
+
|
| 337 |
+
def prepare_for_tokenization(self, text, **kwargs):
|
| 338 |
+
text = unicodedata.normalize("NFC", text)
|
| 339 |
+
return (text, kwargs)
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
__all__ = ["Qwen2Tokenizer"]
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": false,
|
| 3 |
+
"add_prefix_space": false,
|
| 4 |
+
"added_tokens_decoder": {
|
| 5 |
+
"151643": {
|
| 6 |
+
"content": "<|endoftext|>",
|
| 7 |
+
"lstrip": false,
|
| 8 |
+
"normalized": false,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false,
|
| 11 |
+
"special": true
|
| 12 |
+
},
|
| 13 |
+
"151644": {
|
| 14 |
+
"content": "<|im_start|>",
|
| 15 |
+
"lstrip": false,
|
| 16 |
+
"normalized": false,
|
| 17 |
+
"rstrip": false,
|
| 18 |
+
"single_word": false,
|
| 19 |
+
"special": true
|
| 20 |
+
},
|
| 21 |
+
"151645": {
|
| 22 |
+
"content": "<|im_end|>",
|
| 23 |
+
"lstrip": false,
|
| 24 |
+
"normalized": false,
|
| 25 |
+
"rstrip": false,
|
| 26 |
+
"single_word": false,
|
| 27 |
+
"special": true
|
| 28 |
+
},
|
| 29 |
+
"151646": {
|
| 30 |
+
"content": "<|object_ref_start|>",
|
| 31 |
+
"lstrip": false,
|
| 32 |
+
"normalized": false,
|
| 33 |
+
"rstrip": false,
|
| 34 |
+
"single_word": false,
|
| 35 |
+
"special": true
|
| 36 |
+
},
|
| 37 |
+
"151647": {
|
| 38 |
+
"content": "<|object_ref_end|>",
|
| 39 |
+
"lstrip": false,
|
| 40 |
+
"normalized": false,
|
| 41 |
+
"rstrip": false,
|
| 42 |
+
"single_word": false,
|
| 43 |
+
"special": true
|
| 44 |
+
},
|
| 45 |
+
"151648": {
|
| 46 |
+
"content": "<|box_start|>",
|
| 47 |
+
"lstrip": false,
|
| 48 |
+
"normalized": false,
|
| 49 |
+
"rstrip": false,
|
| 50 |
+
"single_word": false,
|
| 51 |
+
"special": true
|
| 52 |
+
},
|
| 53 |
+
"151649": {
|
| 54 |
+
"content": "<|box_end|>",
|
| 55 |
+
"lstrip": false,
|
| 56 |
+
"normalized": false,
|
| 57 |
+
"rstrip": false,
|
| 58 |
+
"single_word": false,
|
| 59 |
+
"special": true
|
| 60 |
+
},
|
| 61 |
+
"151650": {
|
| 62 |
+
"content": "<|quad_start|>",
|
| 63 |
+
"lstrip": false,
|
| 64 |
+
"normalized": false,
|
| 65 |
+
"rstrip": false,
|
| 66 |
+
"single_word": false,
|
| 67 |
+
"special": true
|
| 68 |
+
},
|
| 69 |
+
"151651": {
|
| 70 |
+
"content": "<|quad_end|>",
|
| 71 |
+
"lstrip": false,
|
| 72 |
+
"normalized": false,
|
| 73 |
+
"rstrip": false,
|
| 74 |
+
"single_word": false,
|
| 75 |
+
"special": true
|
| 76 |
+
},
|
| 77 |
+
"151652": {
|
| 78 |
+
"content": "<|vision_start|>",
|
| 79 |
+
"lstrip": false,
|
| 80 |
+
"normalized": false,
|
| 81 |
+
"rstrip": false,
|
| 82 |
+
"single_word": false,
|
| 83 |
+
"special": true
|
| 84 |
+
},
|
| 85 |
+
"151653": {
|
| 86 |
+
"content": "<|vision_end|>",
|
| 87 |
+
"lstrip": false,
|
| 88 |
+
"normalized": false,
|
| 89 |
+
"rstrip": false,
|
| 90 |
+
"single_word": false,
|
| 91 |
+
"special": true
|
| 92 |
+
},
|
| 93 |
+
"151654": {
|
| 94 |
+
"content": "<|vision_pad|>",
|
| 95 |
+
"lstrip": false,
|
| 96 |
+
"normalized": false,
|
| 97 |
+
"rstrip": false,
|
| 98 |
+
"single_word": false,
|
| 99 |
+
"special": true
|
| 100 |
+
},
|
| 101 |
+
"151655": {
|
| 102 |
+
"content": "<|image_pad|>",
|
| 103 |
+
"lstrip": false,
|
| 104 |
+
"normalized": false,
|
| 105 |
+
"rstrip": false,
|
| 106 |
+
"single_word": false,
|
| 107 |
+
"special": true
|
| 108 |
+
},
|
| 109 |
+
"151656": {
|
| 110 |
+
"content": "<|video_pad|>",
|
| 111 |
+
"lstrip": false,
|
| 112 |
+
"normalized": false,
|
| 113 |
+
"rstrip": false,
|
| 114 |
+
"single_word": false,
|
| 115 |
+
"special": true
|
| 116 |
+
},
|
| 117 |
+
"151657": {
|
| 118 |
+
"content": "<tool_call>",
|
| 119 |
+
"lstrip": false,
|
| 120 |
+
"normalized": false,
|
| 121 |
+
"rstrip": false,
|
| 122 |
+
"single_word": false,
|
| 123 |
+
"special": false
|
| 124 |
+
},
|
| 125 |
+
"151658": {
|
| 126 |
+
"content": "</tool_call>",
|
| 127 |
+
"lstrip": false,
|
| 128 |
+
"normalized": false,
|
| 129 |
+
"rstrip": false,
|
| 130 |
+
"single_word": false,
|
| 131 |
+
"special": false
|
| 132 |
+
},
|
| 133 |
+
"151659": {
|
| 134 |
+
"content": "<|fim_prefix|>",
|
| 135 |
+
"lstrip": false,
|
| 136 |
+
"normalized": false,
|
| 137 |
+
"rstrip": false,
|
| 138 |
+
"single_word": false,
|
| 139 |
+
"special": false
|
| 140 |
+
},
|
| 141 |
+
"151660": {
|
| 142 |
+
"content": "<|fim_middle|>",
|
| 143 |
+
"lstrip": false,
|
| 144 |
+
"normalized": false,
|
| 145 |
+
"rstrip": false,
|
| 146 |
+
"single_word": false,
|
| 147 |
+
"special": false
|
| 148 |
+
},
|
| 149 |
+
"151661": {
|
| 150 |
+
"content": "<|fim_suffix|>",
|
| 151 |
+
"lstrip": false,
|
| 152 |
+
"normalized": false,
|
| 153 |
+
"rstrip": false,
|
| 154 |
+
"single_word": false,
|
| 155 |
+
"special": false
|
| 156 |
+
},
|
| 157 |
+
"151662": {
|
| 158 |
+
"content": "<|fim_pad|>",
|
| 159 |
+
"lstrip": false,
|
| 160 |
+
"normalized": false,
|
| 161 |
+
"rstrip": false,
|
| 162 |
+
"single_word": false,
|
| 163 |
+
"special": false
|
| 164 |
+
},
|
| 165 |
+
"151663": {
|
| 166 |
+
"content": "<|repo_name|>",
|
| 167 |
+
"lstrip": false,
|
| 168 |
+
"normalized": false,
|
| 169 |
+
"rstrip": false,
|
| 170 |
+
"single_word": false,
|
| 171 |
+
"special": false
|
| 172 |
+
},
|
| 173 |
+
"151664": {
|
| 174 |
+
"content": "<|file_sep|>",
|
| 175 |
+
"lstrip": false,
|
| 176 |
+
"normalized": false,
|
| 177 |
+
"rstrip": false,
|
| 178 |
+
"single_word": false,
|
| 179 |
+
"special": false
|
| 180 |
+
},
|
| 181 |
+
"151665": {
|
| 182 |
+
"content": "<tool_response>",
|
| 183 |
+
"lstrip": false,
|
| 184 |
+
"normalized": false,
|
| 185 |
+
"rstrip": false,
|
| 186 |
+
"single_word": false,
|
| 187 |
+
"special": false
|
| 188 |
+
},
|
| 189 |
+
"151666": {
|
| 190 |
+
"content": "</tool_response>",
|
| 191 |
+
"lstrip": false,
|
| 192 |
+
"normalized": false,
|
| 193 |
+
"rstrip": false,
|
| 194 |
+
"single_word": false,
|
| 195 |
+
"special": false
|
| 196 |
+
},
|
| 197 |
+
"151667": {
|
| 198 |
+
"content": "<think>",
|
| 199 |
+
"lstrip": false,
|
| 200 |
+
"normalized": false,
|
| 201 |
+
"rstrip": false,
|
| 202 |
+
"single_word": false,
|
| 203 |
+
"special": false
|
| 204 |
+
},
|
| 205 |
+
"151668": {
|
| 206 |
+
"content": "</think>",
|
| 207 |
+
"lstrip": false,
|
| 208 |
+
"normalized": false,
|
| 209 |
+
"rstrip": false,
|
| 210 |
+
"single_word": false,
|
| 211 |
+
"special": false
|
| 212 |
+
},
|
| 213 |
+
"151669": {
|
| 214 |
+
"content": "<|MASK|>",
|
| 215 |
+
"lstrip": false,
|
| 216 |
+
"normalized": false,
|
| 217 |
+
"rstrip": false,
|
| 218 |
+
"single_word": false,
|
| 219 |
+
"special": true
|
| 220 |
+
},
|
| 221 |
+
"151670": {
|
| 222 |
+
"content": "<EOB>",
|
| 223 |
+
"lstrip": false,
|
| 224 |
+
"normalized": false,
|
| 225 |
+
"rstrip": false,
|
| 226 |
+
"single_word": false,
|
| 227 |
+
"special": true
|
| 228 |
+
}
|
| 229 |
+
},
|
| 230 |
+
"additional_special_tokens": [
|
| 231 |
+
"<|im_start|>",
|
| 232 |
+
"<|im_end|>",
|
| 233 |
+
"<|object_ref_start|>",
|
| 234 |
+
"<|object_ref_end|>",
|
| 235 |
+
"<|box_start|>",
|
| 236 |
+
"<|box_end|>",
|
| 237 |
+
"<|quad_start|>",
|
| 238 |
+
"<|quad_end|>",
|
| 239 |
+
"<|vision_start|>",
|
| 240 |
+
"<|vision_end|>",
|
| 241 |
+
"<|vision_pad|>",
|
| 242 |
+
"<|image_pad|>",
|
| 243 |
+
"<|video_pad|>",
|
| 244 |
+
"<|MASK|>",
|
| 245 |
+
"<EOB>"
|
| 246 |
+
],
|
| 247 |
+
"auto_map": {
|
| 248 |
+
"AutoTokenizer": [
|
| 249 |
+
"tokenization_qwen2.Qwen2Tokenizer",
|
| 250 |
+
null
|
| 251 |
+
]
|
| 252 |
+
},
|
| 253 |
+
"bos_token": null,
|
| 254 |
+
"clean_up_tokenization_spaces": false,
|
| 255 |
+
"eos_token": "<|im_end|>",
|
| 256 |
+
"errors": "replace",
|
| 257 |
+
"extra_special_tokens": {},
|
| 258 |
+
"mask_token": "<|MASK|>",
|
| 259 |
+
"model_max_length": 131072,
|
| 260 |
+
"pad_token": "<|endoftext|>",
|
| 261 |
+
"padding_side": "right",
|
| 262 |
+
"split_special_tokens": false,
|
| 263 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 264 |
+
"unk_token": null
|
| 265 |
+
}
|
trainer_state.json
ADDED
|
@@ -0,0 +1,2204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
"eval_steps": 500,
|
| 7 |
+
"global_step": 1550,
|
| 8 |
+
"is_hyper_param_search": false,
|
| 9 |
+
"is_local_process_zero": true,
|
| 10 |
+
"is_world_process_zero": true,
|
| 11 |
+
"log_history": [
|
| 12 |
+
{
|
| 13 |
+
"epoch": 0.0067613252197430695,
|
| 14 |
+
"grad_norm": 1272.255859375,
|
| 15 |
+
"learning_rate": 5.970149253731343e-07,
|
| 16 |
+
"loss": 37.2004,
|
| 17 |
+
"step": 5
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"epoch": 0.013522650439486139,
|
| 21 |
+
"grad_norm": 538.208251953125,
|
| 22 |
+
"learning_rate": 1.3432835820895524e-06,
|
| 23 |
+
"loss": 34.1505,
|
| 24 |
+
"step": 10
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"epoch": 0.02028397565922921,
|
| 28 |
+
"grad_norm": 241.84115600585938,
|
| 29 |
+
"learning_rate": 2.08955223880597e-06,
|
| 30 |
+
"loss": 27.7417,
|
| 31 |
+
"step": 15
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"epoch": 0.027045300878972278,
|
| 35 |
+
"grad_norm": 149.00253295898438,
|
| 36 |
+
"learning_rate": 2.835820895522388e-06,
|
| 37 |
+
"loss": 22.3086,
|
| 38 |
+
"step": 20
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"epoch": 0.03380662609871535,
|
| 42 |
+
"grad_norm": 137.87466430664062,
|
| 43 |
+
"learning_rate": 3.582089552238806e-06,
|
| 44 |
+
"loss": 19.628,
|
| 45 |
+
"step": 25
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"epoch": 0.04056795131845842,
|
| 49 |
+
"grad_norm": 166.65280151367188,
|
| 50 |
+
"learning_rate": 4.3283582089552236e-06,
|
| 51 |
+
"loss": 17.6907,
|
| 52 |
+
"step": 30
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"epoch": 0.04732927653820149,
|
| 56 |
+
"grad_norm": 215.9780731201172,
|
| 57 |
+
"learning_rate": 5.074626865671642e-06,
|
| 58 |
+
"loss": 16.4974,
|
| 59 |
+
"step": 35
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"epoch": 0.054090601757944556,
|
| 63 |
+
"grad_norm": 223.51185607910156,
|
| 64 |
+
"learning_rate": 5.820895522388061e-06,
|
| 65 |
+
"loss": 15.188,
|
| 66 |
+
"step": 40
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"epoch": 0.060851926977687626,
|
| 70 |
+
"grad_norm": 225.0447998046875,
|
| 71 |
+
"learning_rate": 6.567164179104478e-06,
|
| 72 |
+
"loss": 14.3741,
|
| 73 |
+
"step": 45
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"epoch": 0.0676132521974307,
|
| 77 |
+
"grad_norm": 224.58688354492188,
|
| 78 |
+
"learning_rate": 7.313432835820896e-06,
|
| 79 |
+
"loss": 13.2594,
|
| 80 |
+
"step": 50
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"epoch": 0.07437457741717377,
|
| 84 |
+
"grad_norm": 227.6384735107422,
|
| 85 |
+
"learning_rate": 8.059701492537314e-06,
|
| 86 |
+
"loss": 12.5621,
|
| 87 |
+
"step": 55
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"epoch": 0.08113590263691683,
|
| 91 |
+
"grad_norm": 221.85934448242188,
|
| 92 |
+
"learning_rate": 8.805970149253732e-06,
|
| 93 |
+
"loss": 11.5079,
|
| 94 |
+
"step": 60
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"epoch": 0.0878972278566599,
|
| 98 |
+
"grad_norm": 216.83883666992188,
|
| 99 |
+
"learning_rate": 9.552238805970149e-06,
|
| 100 |
+
"loss": 10.5443,
|
| 101 |
+
"step": 65
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"epoch": 0.09465855307640297,
|
| 105 |
+
"grad_norm": 207.60470581054688,
|
| 106 |
+
"learning_rate": 9.999978708249054e-06,
|
| 107 |
+
"loss": 9.3134,
|
| 108 |
+
"step": 70
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"epoch": 0.10141987829614604,
|
| 112 |
+
"grad_norm": 200.57904052734375,
|
| 113 |
+
"learning_rate": 9.999739178133424e-06,
|
| 114 |
+
"loss": 8.1168,
|
| 115 |
+
"step": 75
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"epoch": 0.10818120351588911,
|
| 119 |
+
"grad_norm": 187.943603515625,
|
| 120 |
+
"learning_rate": 9.999233516005972e-06,
|
| 121 |
+
"loss": 7.0911,
|
| 122 |
+
"step": 80
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"epoch": 0.11494252873563218,
|
| 126 |
+
"grad_norm": 162.5326385498047,
|
| 127 |
+
"learning_rate": 9.99846174878268e-06,
|
| 128 |
+
"loss": 6.1073,
|
| 129 |
+
"step": 85
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"epoch": 0.12170385395537525,
|
| 133 |
+
"grad_norm": 120.48332214355469,
|
| 134 |
+
"learning_rate": 9.99742391754408e-06,
|
| 135 |
+
"loss": 5.2959,
|
| 136 |
+
"step": 90
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"epoch": 0.12846517917511832,
|
| 140 |
+
"grad_norm": 75.04917907714844,
|
| 141 |
+
"learning_rate": 9.99612007753308e-06,
|
| 142 |
+
"loss": 4.682,
|
| 143 |
+
"step": 95
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"epoch": 0.1352265043948614,
|
| 147 |
+
"grad_norm": 41.34440612792969,
|
| 148 |
+
"learning_rate": 9.994550298152012e-06,
|
| 149 |
+
"loss": 4.2617,
|
| 150 |
+
"step": 100
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"epoch": 0.14198782961460446,
|
| 154 |
+
"grad_norm": 25.1535587310791,
|
| 155 |
+
"learning_rate": 9.992714662958944e-06,
|
| 156 |
+
"loss": 3.962,
|
| 157 |
+
"step": 105
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"epoch": 0.14874915483434753,
|
| 161 |
+
"grad_norm": 15.239022254943848,
|
| 162 |
+
"learning_rate": 9.990613269663231e-06,
|
| 163 |
+
"loss": 3.789,
|
| 164 |
+
"step": 110
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"epoch": 0.1555104800540906,
|
| 168 |
+
"grad_norm": 17.221874237060547,
|
| 169 |
+
"learning_rate": 9.988246230120311e-06,
|
| 170 |
+
"loss": 3.6555,
|
| 171 |
+
"step": 115
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
"epoch": 0.16227180527383367,
|
| 175 |
+
"grad_norm": 10.792862892150879,
|
| 176 |
+
"learning_rate": 9.985613670325759e-06,
|
| 177 |
+
"loss": 3.4862,
|
| 178 |
+
"step": 120
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"epoch": 0.16903313049357674,
|
| 182 |
+
"grad_norm": 7.69727897644043,
|
| 183 |
+
"learning_rate": 9.982715730408568e-06,
|
| 184 |
+
"loss": 3.3919,
|
| 185 |
+
"step": 125
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"epoch": 0.1757944557133198,
|
| 189 |
+
"grad_norm": 7.8089118003845215,
|
| 190 |
+
"learning_rate": 9.979552564623703e-06,
|
| 191 |
+
"loss": 3.3046,
|
| 192 |
+
"step": 130
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"epoch": 0.18255578093306288,
|
| 196 |
+
"grad_norm": 8.153103828430176,
|
| 197 |
+
"learning_rate": 9.97612434134388e-06,
|
| 198 |
+
"loss": 3.2778,
|
| 199 |
+
"step": 135
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"epoch": 0.18931710615280595,
|
| 203 |
+
"grad_norm": 6.2102484703063965,
|
| 204 |
+
"learning_rate": 9.972431243050611e-06,
|
| 205 |
+
"loss": 3.1411,
|
| 206 |
+
"step": 140
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"epoch": 0.19607843137254902,
|
| 210 |
+
"grad_norm": 4.64615535736084,
|
| 211 |
+
"learning_rate": 9.968473466324486e-06,
|
| 212 |
+
"loss": 3.1302,
|
| 213 |
+
"step": 145
|
| 214 |
+
},
|
| 215 |
+
{
|
| 216 |
+
"epoch": 0.2028397565922921,
|
| 217 |
+
"grad_norm": 6.153476238250732,
|
| 218 |
+
"learning_rate": 9.964251221834712e-06,
|
| 219 |
+
"loss": 3.1216,
|
| 220 |
+
"step": 150
|
| 221 |
+
},
|
| 222 |
+
{
|
| 223 |
+
"epoch": 0.20960108181203516,
|
| 224 |
+
"grad_norm": 4.58518648147583,
|
| 225 |
+
"learning_rate": 9.959764734327894e-06,
|
| 226 |
+
"loss": 3.0453,
|
| 227 |
+
"step": 155
|
| 228 |
+
},
|
| 229 |
+
{
|
| 230 |
+
"epoch": 0.21636240703177823,
|
| 231 |
+
"grad_norm": 5.034542560577393,
|
| 232 |
+
"learning_rate": 9.955014242616083e-06,
|
| 233 |
+
"loss": 3.0575,
|
| 234 |
+
"step": 160
|
| 235 |
+
},
|
| 236 |
+
{
|
| 237 |
+
"epoch": 0.2231237322515213,
|
| 238 |
+
"grad_norm": 5.907400608062744,
|
| 239 |
+
"learning_rate": 9.949999999564049e-06,
|
| 240 |
+
"loss": 3.045,
|
| 241 |
+
"step": 165
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
"epoch": 0.22988505747126436,
|
| 245 |
+
"grad_norm": 5.186819553375244,
|
| 246 |
+
"learning_rate": 9.944722272075834e-06,
|
| 247 |
+
"loss": 3.0121,
|
| 248 |
+
"step": 170
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"epoch": 0.23664638269100743,
|
| 252 |
+
"grad_norm": 5.540721416473389,
|
| 253 |
+
"learning_rate": 9.93918134108054e-06,
|
| 254 |
+
"loss": 2.9834,
|
| 255 |
+
"step": 175
|
| 256 |
+
},
|
| 257 |
+
{
|
| 258 |
+
"epoch": 0.2434077079107505,
|
| 259 |
+
"grad_norm": 5.014519214630127,
|
| 260 |
+
"learning_rate": 9.933377501517375e-06,
|
| 261 |
+
"loss": 2.9621,
|
| 262 |
+
"step": 180
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
"epoch": 0.2501690331304936,
|
| 266 |
+
"grad_norm": 5.306411266326904,
|
| 267 |
+
"learning_rate": 9.927311062319953e-06,
|
| 268 |
+
"loss": 2.9895,
|
| 269 |
+
"step": 185
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"epoch": 0.25693035835023664,
|
| 273 |
+
"grad_norm": 3.703613042831421,
|
| 274 |
+
"learning_rate": 9.920982346399854e-06,
|
| 275 |
+
"loss": 2.9428,
|
| 276 |
+
"step": 190
|
| 277 |
+
},
|
| 278 |
+
{
|
| 279 |
+
"epoch": 0.26369168356997974,
|
| 280 |
+
"grad_norm": 4.594870567321777,
|
| 281 |
+
"learning_rate": 9.91439169062943e-06,
|
| 282 |
+
"loss": 2.9494,
|
| 283 |
+
"step": 195
|
| 284 |
+
},
|
| 285 |
+
{
|
| 286 |
+
"epoch": 0.2704530087897228,
|
| 287 |
+
"grad_norm": 3.66827130317688,
|
| 288 |
+
"learning_rate": 9.907539445823877e-06,
|
| 289 |
+
"loss": 2.9214,
|
| 290 |
+
"step": 200
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"epoch": 0.2772143340094659,
|
| 294 |
+
"grad_norm": 4.361055850982666,
|
| 295 |
+
"learning_rate": 9.90042597672256e-06,
|
| 296 |
+
"loss": 2.9404,
|
| 297 |
+
"step": 205
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"epoch": 0.2839756592292089,
|
| 301 |
+
"grad_norm": 4.3119916915893555,
|
| 302 |
+
"learning_rate": 9.893051661969599e-06,
|
| 303 |
+
"loss": 2.9174,
|
| 304 |
+
"step": 210
|
| 305 |
+
},
|
| 306 |
+
{
|
| 307 |
+
"epoch": 0.290736984448952,
|
| 308 |
+
"grad_norm": 3.507157325744629,
|
| 309 |
+
"learning_rate": 9.885416894093714e-06,
|
| 310 |
+
"loss": 2.9036,
|
| 311 |
+
"step": 215
|
| 312 |
+
},
|
| 313 |
+
{
|
| 314 |
+
"epoch": 0.29749830966869506,
|
| 315 |
+
"grad_norm": 4.4753522872924805,
|
| 316 |
+
"learning_rate": 9.877522079487334e-06,
|
| 317 |
+
"loss": 2.905,
|
| 318 |
+
"step": 220
|
| 319 |
+
},
|
| 320 |
+
{
|
| 321 |
+
"epoch": 0.30425963488843816,
|
| 322 |
+
"grad_norm": 3.661130666732788,
|
| 323 |
+
"learning_rate": 9.869367638384955e-06,
|
| 324 |
+
"loss": 2.904,
|
| 325 |
+
"step": 225
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"epoch": 0.3110209601081812,
|
| 329 |
+
"grad_norm": 3.0701863765716553,
|
| 330 |
+
"learning_rate": 9.860954004840787e-06,
|
| 331 |
+
"loss": 2.8509,
|
| 332 |
+
"step": 230
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"epoch": 0.3177822853279243,
|
| 336 |
+
"grad_norm": 3.502415895462036,
|
| 337 |
+
"learning_rate": 9.85228162670563e-06,
|
| 338 |
+
"loss": 2.8465,
|
| 339 |
+
"step": 235
|
| 340 |
+
},
|
| 341 |
+
{
|
| 342 |
+
"epoch": 0.32454361054766734,
|
| 343 |
+
"grad_norm": 3.181335210800171,
|
| 344 |
+
"learning_rate": 9.843350965603058e-06,
|
| 345 |
+
"loss": 2.859,
|
| 346 |
+
"step": 240
|
| 347 |
+
},
|
| 348 |
+
{
|
| 349 |
+
"epoch": 0.33130493576741044,
|
| 350 |
+
"grad_norm": 3.8409316539764404,
|
| 351 |
+
"learning_rate": 9.834162496904827e-06,
|
| 352 |
+
"loss": 2.8176,
|
| 353 |
+
"step": 245
|
| 354 |
+
},
|
| 355 |
+
{
|
| 356 |
+
"epoch": 0.3380662609871535,
|
| 357 |
+
"grad_norm": 3.99033522605896,
|
| 358 |
+
"learning_rate": 9.824716709705584e-06,
|
| 359 |
+
"loss": 2.7968,
|
| 360 |
+
"step": 250
|
| 361 |
+
},
|
| 362 |
+
{
|
| 363 |
+
"epoch": 0.3448275862068966,
|
| 364 |
+
"grad_norm": 3.110179901123047,
|
| 365 |
+
"learning_rate": 9.815014106796824e-06,
|
| 366 |
+
"loss": 2.8209,
|
| 367 |
+
"step": 255
|
| 368 |
+
},
|
| 369 |
+
{
|
| 370 |
+
"epoch": 0.3515889114266396,
|
| 371 |
+
"grad_norm": 3.054056167602539,
|
| 372 |
+
"learning_rate": 9.805055204640138e-06,
|
| 373 |
+
"loss": 2.8437,
|
| 374 |
+
"step": 260
|
| 375 |
+
},
|
| 376 |
+
{
|
| 377 |
+
"epoch": 0.3583502366463827,
|
| 378 |
+
"grad_norm": 3.178157091140747,
|
| 379 |
+
"learning_rate": 9.79484053333971e-06,
|
| 380 |
+
"loss": 2.808,
|
| 381 |
+
"step": 265
|
| 382 |
+
},
|
| 383 |
+
{
|
| 384 |
+
"epoch": 0.36511156186612576,
|
| 385 |
+
"grad_norm": 3.8207147121429443,
|
| 386 |
+
"learning_rate": 9.784370636614107e-06,
|
| 387 |
+
"loss": 2.7898,
|
| 388 |
+
"step": 270
|
| 389 |
+
},
|
| 390 |
+
{
|
| 391 |
+
"epoch": 0.37187288708586885,
|
| 392 |
+
"grad_norm": 6.010393142700195,
|
| 393 |
+
"learning_rate": 9.773646071767338e-06,
|
| 394 |
+
"loss": 2.7979,
|
| 395 |
+
"step": 275
|
| 396 |
+
},
|
| 397 |
+
{
|
| 398 |
+
"epoch": 0.3786342123056119,
|
| 399 |
+
"grad_norm": 3.476896047592163,
|
| 400 |
+
"learning_rate": 9.762667409659183e-06,
|
| 401 |
+
"loss": 2.7783,
|
| 402 |
+
"step": 280
|
| 403 |
+
},
|
| 404 |
+
{
|
| 405 |
+
"epoch": 0.385395537525355,
|
| 406 |
+
"grad_norm": 3.391853094100952,
|
| 407 |
+
"learning_rate": 9.751435234674813e-06,
|
| 408 |
+
"loss": 2.7708,
|
| 409 |
+
"step": 285
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
"epoch": 0.39215686274509803,
|
| 413 |
+
"grad_norm": 3.346642255783081,
|
| 414 |
+
"learning_rate": 9.739950144693681e-06,
|
| 415 |
+
"loss": 2.7825,
|
| 416 |
+
"step": 290
|
| 417 |
+
},
|
| 418 |
+
{
|
| 419 |
+
"epoch": 0.39891818796484113,
|
| 420 |
+
"grad_norm": 3.348356008529663,
|
| 421 |
+
"learning_rate": 9.728212751057701e-06,
|
| 422 |
+
"loss": 2.744,
|
| 423 |
+
"step": 295
|
| 424 |
+
},
|
| 425 |
+
{
|
| 426 |
+
"epoch": 0.4056795131845842,
|
| 427 |
+
"grad_norm": 3.324674129486084,
|
| 428 |
+
"learning_rate": 9.716223678538699e-06,
|
| 429 |
+
"loss": 2.7587,
|
| 430 |
+
"step": 300
|
| 431 |
+
},
|
| 432 |
+
{
|
| 433 |
+
"epoch": 0.41244083840432727,
|
| 434 |
+
"grad_norm": 3.0210790634155273,
|
| 435 |
+
"learning_rate": 9.70398356530516e-06,
|
| 436 |
+
"loss": 2.7832,
|
| 437 |
+
"step": 305
|
| 438 |
+
},
|
| 439 |
+
{
|
| 440 |
+
"epoch": 0.4192021636240703,
|
| 441 |
+
"grad_norm": 3.3017354011535645,
|
| 442 |
+
"learning_rate": 9.691493062888264e-06,
|
| 443 |
+
"loss": 2.7574,
|
| 444 |
+
"step": 310
|
| 445 |
+
},
|
| 446 |
+
{
|
| 447 |
+
"epoch": 0.4259634888438134,
|
| 448 |
+
"grad_norm": 2.9814178943634033,
|
| 449 |
+
"learning_rate": 9.6787528361472e-06,
|
| 450 |
+
"loss": 2.7481,
|
| 451 |
+
"step": 315
|
| 452 |
+
},
|
| 453 |
+
{
|
| 454 |
+
"epoch": 0.43272481406355645,
|
| 455 |
+
"grad_norm": 2.686392307281494,
|
| 456 |
+
"learning_rate": 9.66576356323378e-06,
|
| 457 |
+
"loss": 2.7586,
|
| 458 |
+
"step": 320
|
| 459 |
+
},
|
| 460 |
+
{
|
| 461 |
+
"epoch": 0.43948613928329955,
|
| 462 |
+
"grad_norm": 3.3055434226989746,
|
| 463 |
+
"learning_rate": 9.652525935556335e-06,
|
| 464 |
+
"loss": 2.735,
|
| 465 |
+
"step": 325
|
| 466 |
+
},
|
| 467 |
+
{
|
| 468 |
+
"epoch": 0.4462474645030426,
|
| 469 |
+
"grad_norm": 3.388873338699341,
|
| 470 |
+
"learning_rate": 9.63904065774292e-06,
|
| 471 |
+
"loss": 2.758,
|
| 472 |
+
"step": 330
|
| 473 |
+
},
|
| 474 |
+
{
|
| 475 |
+
"epoch": 0.4530087897227857,
|
| 476 |
+
"grad_norm": 3.3133444786071777,
|
| 477 |
+
"learning_rate": 9.625308447603801e-06,
|
| 478 |
+
"loss": 2.734,
|
| 479 |
+
"step": 335
|
| 480 |
+
},
|
| 481 |
+
{
|
| 482 |
+
"epoch": 0.45977011494252873,
|
| 483 |
+
"grad_norm": 2.6662232875823975,
|
| 484 |
+
"learning_rate": 9.611330036093252e-06,
|
| 485 |
+
"loss": 2.755,
|
| 486 |
+
"step": 340
|
| 487 |
+
},
|
| 488 |
+
{
|
| 489 |
+
"epoch": 0.4665314401622718,
|
| 490 |
+
"grad_norm": 3.3504395484924316,
|
| 491 |
+
"learning_rate": 9.59710616727064e-06,
|
| 492 |
+
"loss": 2.7532,
|
| 493 |
+
"step": 345
|
| 494 |
+
},
|
| 495 |
+
{
|
| 496 |
+
"epoch": 0.47329276538201487,
|
| 497 |
+
"grad_norm": 3.4668731689453125,
|
| 498 |
+
"learning_rate": 9.582637598260824e-06,
|
| 499 |
+
"loss": 2.7325,
|
| 500 |
+
"step": 350
|
| 501 |
+
},
|
| 502 |
+
{
|
| 503 |
+
"epoch": 0.48005409060175797,
|
| 504 |
+
"grad_norm": 3.009427785873413,
|
| 505 |
+
"learning_rate": 9.567925099213857e-06,
|
| 506 |
+
"loss": 2.7179,
|
| 507 |
+
"step": 355
|
| 508 |
+
},
|
| 509 |
+
{
|
| 510 |
+
"epoch": 0.486815415821501,
|
| 511 |
+
"grad_norm": 3.1236302852630615,
|
| 512 |
+
"learning_rate": 9.552969453263983e-06,
|
| 513 |
+
"loss": 2.7613,
|
| 514 |
+
"step": 360
|
| 515 |
+
},
|
| 516 |
+
{
|
| 517 |
+
"epoch": 0.4935767410412441,
|
| 518 |
+
"grad_norm": 3.0972957611083984,
|
| 519 |
+
"learning_rate": 9.537771456487959e-06,
|
| 520 |
+
"loss": 2.7275,
|
| 521 |
+
"step": 365
|
| 522 |
+
},
|
| 523 |
+
{
|
| 524 |
+
"epoch": 0.5003380662609872,
|
| 525 |
+
"grad_norm": 2.5772786140441895,
|
| 526 |
+
"learning_rate": 9.522331917862674e-06,
|
| 527 |
+
"loss": 2.7529,
|
| 528 |
+
"step": 370
|
| 529 |
+
},
|
| 530 |
+
{
|
| 531 |
+
"epoch": 0.5070993914807302,
|
| 532 |
+
"grad_norm": 3.032407760620117,
|
| 533 |
+
"learning_rate": 9.506651659222096e-06,
|
| 534 |
+
"loss": 2.7065,
|
| 535 |
+
"step": 375
|
| 536 |
+
},
|
| 537 |
+
{
|
| 538 |
+
"epoch": 0.5138607167004733,
|
| 539 |
+
"grad_norm": 2.7317681312561035,
|
| 540 |
+
"learning_rate": 9.49073151521352e-06,
|
| 541 |
+
"loss": 2.7036,
|
| 542 |
+
"step": 380
|
| 543 |
+
},
|
| 544 |
+
{
|
| 545 |
+
"epoch": 0.5206220419202163,
|
| 546 |
+
"grad_norm": 3.070013999938965,
|
| 547 |
+
"learning_rate": 9.47457233325314e-06,
|
| 548 |
+
"loss": 2.705,
|
| 549 |
+
"step": 385
|
| 550 |
+
},
|
| 551 |
+
{
|
| 552 |
+
"epoch": 0.5273833671399595,
|
| 553 |
+
"grad_norm": 3.1261889934539795,
|
| 554 |
+
"learning_rate": 9.458174973480945e-06,
|
| 555 |
+
"loss": 2.7006,
|
| 556 |
+
"step": 390
|
| 557 |
+
},
|
| 558 |
+
{
|
| 559 |
+
"epoch": 0.5341446923597025,
|
| 560 |
+
"grad_norm": 2.8663241863250732,
|
| 561 |
+
"learning_rate": 9.441540308714934e-06,
|
| 562 |
+
"loss": 2.7197,
|
| 563 |
+
"step": 395
|
| 564 |
+
},
|
| 565 |
+
{
|
| 566 |
+
"epoch": 0.5409060175794456,
|
| 567 |
+
"grad_norm": 3.94987416267395,
|
| 568 |
+
"learning_rate": 9.424669224404659e-06,
|
| 569 |
+
"loss": 2.7162,
|
| 570 |
+
"step": 400
|
| 571 |
+
},
|
| 572 |
+
{
|
| 573 |
+
"epoch": 0.5476673427991886,
|
| 574 |
+
"grad_norm": 2.7462100982666016,
|
| 575 |
+
"learning_rate": 9.407562618584083e-06,
|
| 576 |
+
"loss": 2.662,
|
| 577 |
+
"step": 405
|
| 578 |
+
},
|
| 579 |
+
{
|
| 580 |
+
"epoch": 0.5544286680189318,
|
| 581 |
+
"grad_norm": 2.9217984676361084,
|
| 582 |
+
"learning_rate": 9.390221401823793e-06,
|
| 583 |
+
"loss": 2.6988,
|
| 584 |
+
"step": 410
|
| 585 |
+
},
|
| 586 |
+
{
|
| 587 |
+
"epoch": 0.5611899932386748,
|
| 588 |
+
"grad_norm": 3.6465213298797607,
|
| 589 |
+
"learning_rate": 9.372646497182519e-06,
|
| 590 |
+
"loss": 2.6772,
|
| 591 |
+
"step": 415
|
| 592 |
+
},
|
| 593 |
+
{
|
| 594 |
+
"epoch": 0.5679513184584178,
|
| 595 |
+
"grad_norm": 3.873567581176758,
|
| 596 |
+
"learning_rate": 9.354838840158006e-06,
|
| 597 |
+
"loss": 2.6699,
|
| 598 |
+
"step": 420
|
| 599 |
+
},
|
| 600 |
+
{
|
| 601 |
+
"epoch": 0.5747126436781609,
|
| 602 |
+
"grad_norm": 3.826775550842285,
|
| 603 |
+
"learning_rate": 9.33679937863722e-06,
|
| 604 |
+
"loss": 2.6944,
|
| 605 |
+
"step": 425
|
| 606 |
+
},
|
| 607 |
+
{
|
| 608 |
+
"epoch": 0.581473968897904,
|
| 609 |
+
"grad_norm": 3.7498714923858643,
|
| 610 |
+
"learning_rate": 9.318529072845885e-06,
|
| 611 |
+
"loss": 2.6897,
|
| 612 |
+
"step": 430
|
| 613 |
+
},
|
| 614 |
+
{
|
| 615 |
+
"epoch": 0.5882352941176471,
|
| 616 |
+
"grad_norm": 3.4026408195495605,
|
| 617 |
+
"learning_rate": 9.300028895297382e-06,
|
| 618 |
+
"loss": 2.6942,
|
| 619 |
+
"step": 435
|
| 620 |
+
},
|
| 621 |
+
{
|
| 622 |
+
"epoch": 0.5949966193373901,
|
| 623 |
+
"grad_norm": 2.911181688308716,
|
| 624 |
+
"learning_rate": 9.281299830740973e-06,
|
| 625 |
+
"loss": 2.6993,
|
| 626 |
+
"step": 440
|
| 627 |
+
},
|
| 628 |
+
{
|
| 629 |
+
"epoch": 0.6017579445571332,
|
| 630 |
+
"grad_norm": 3.125908613204956,
|
| 631 |
+
"learning_rate": 9.262342876109387e-06,
|
| 632 |
+
"loss": 2.6688,
|
| 633 |
+
"step": 445
|
| 634 |
+
},
|
| 635 |
+
{
|
| 636 |
+
"epoch": 0.6085192697768763,
|
| 637 |
+
"grad_norm": 2.82594895362854,
|
| 638 |
+
"learning_rate": 9.243159040465757e-06,
|
| 639 |
+
"loss": 2.6831,
|
| 640 |
+
"step": 450
|
| 641 |
+
},
|
| 642 |
+
{
|
| 643 |
+
"epoch": 0.6152805949966194,
|
| 644 |
+
"grad_norm": 3.2787418365478516,
|
| 645 |
+
"learning_rate": 9.223749344949904e-06,
|
| 646 |
+
"loss": 2.66,
|
| 647 |
+
"step": 455
|
| 648 |
+
},
|
| 649 |
+
{
|
| 650 |
+
"epoch": 0.6220419202163624,
|
| 651 |
+
"grad_norm": 4.373532772064209,
|
| 652 |
+
"learning_rate": 9.204114822723986e-06,
|
| 653 |
+
"loss": 2.6689,
|
| 654 |
+
"step": 460
|
| 655 |
+
},
|
| 656 |
+
{
|
| 657 |
+
"epoch": 0.6288032454361054,
|
| 658 |
+
"grad_norm": 2.8605294227600098,
|
| 659 |
+
"learning_rate": 9.184256518917504e-06,
|
| 660 |
+
"loss": 2.6509,
|
| 661 |
+
"step": 465
|
| 662 |
+
},
|
| 663 |
+
{
|
| 664 |
+
"epoch": 0.6355645706558486,
|
| 665 |
+
"grad_norm": 4.4151387214660645,
|
| 666 |
+
"learning_rate": 9.164175490571663e-06,
|
| 667 |
+
"loss": 2.6912,
|
| 668 |
+
"step": 470
|
| 669 |
+
},
|
| 670 |
+
{
|
| 671 |
+
"epoch": 0.6423258958755916,
|
| 672 |
+
"grad_norm": 2.953627824783325,
|
| 673 |
+
"learning_rate": 9.143872806583118e-06,
|
| 674 |
+
"loss": 2.6415,
|
| 675 |
+
"step": 475
|
| 676 |
+
},
|
| 677 |
+
{
|
| 678 |
+
"epoch": 0.6490872210953347,
|
| 679 |
+
"grad_norm": 2.935363531112671,
|
| 680 |
+
"learning_rate": 9.12334954764707e-06,
|
| 681 |
+
"loss": 2.6751,
|
| 682 |
+
"step": 480
|
| 683 |
+
},
|
| 684 |
+
{
|
| 685 |
+
"epoch": 0.6558485463150777,
|
| 686 |
+
"grad_norm": 2.8612430095672607,
|
| 687 |
+
"learning_rate": 9.102606806199743e-06,
|
| 688 |
+
"loss": 2.6564,
|
| 689 |
+
"step": 485
|
| 690 |
+
},
|
| 691 |
+
{
|
| 692 |
+
"epoch": 0.6626098715348209,
|
| 693 |
+
"grad_norm": 2.89137864112854,
|
| 694 |
+
"learning_rate": 9.081645686360234e-06,
|
| 695 |
+
"loss": 2.662,
|
| 696 |
+
"step": 490
|
| 697 |
+
},
|
| 698 |
+
{
|
| 699 |
+
"epoch": 0.6693711967545639,
|
| 700 |
+
"grad_norm": 3.100198745727539,
|
| 701 |
+
"learning_rate": 9.060467303871746e-06,
|
| 702 |
+
"loss": 2.6656,
|
| 703 |
+
"step": 495
|
| 704 |
+
},
|
| 705 |
+
{
|
| 706 |
+
"epoch": 0.676132521974307,
|
| 707 |
+
"grad_norm": 2.7693257331848145,
|
| 708 |
+
"learning_rate": 9.039072786042187e-06,
|
| 709 |
+
"loss": 2.6409,
|
| 710 |
+
"step": 500
|
| 711 |
+
},
|
| 712 |
+
{
|
| 713 |
+
"epoch": 0.68289384719405,
|
| 714 |
+
"grad_norm": 3.0061259269714355,
|
| 715 |
+
"learning_rate": 9.017463271684183e-06,
|
| 716 |
+
"loss": 2.6472,
|
| 717 |
+
"step": 505
|
| 718 |
+
},
|
| 719 |
+
{
|
| 720 |
+
"epoch": 0.6896551724137931,
|
| 721 |
+
"grad_norm": 3.591599941253662,
|
| 722 |
+
"learning_rate": 8.995639911054437e-06,
|
| 723 |
+
"loss": 2.6488,
|
| 724 |
+
"step": 510
|
| 725 |
+
},
|
| 726 |
+
{
|
| 727 |
+
"epoch": 0.6964164976335362,
|
| 728 |
+
"grad_norm": 3.120270252227783,
|
| 729 |
+
"learning_rate": 8.973603865792525e-06,
|
| 730 |
+
"loss": 2.6648,
|
| 731 |
+
"step": 515
|
| 732 |
+
},
|
| 733 |
+
{
|
| 734 |
+
"epoch": 0.7031778228532792,
|
| 735 |
+
"grad_norm": 3.2259232997894287,
|
| 736 |
+
"learning_rate": 8.951356308859041e-06,
|
| 737 |
+
"loss": 2.6392,
|
| 738 |
+
"step": 520
|
| 739 |
+
},
|
| 740 |
+
{
|
| 741 |
+
"epoch": 0.7099391480730223,
|
| 742 |
+
"grad_norm": 2.992349624633789,
|
| 743 |
+
"learning_rate": 8.928898424473178e-06,
|
| 744 |
+
"loss": 2.6525,
|
| 745 |
+
"step": 525
|
| 746 |
+
},
|
| 747 |
+
{
|
| 748 |
+
"epoch": 0.7167004732927654,
|
| 749 |
+
"grad_norm": 2.7220916748046875,
|
| 750 |
+
"learning_rate": 8.906231408049682e-06,
|
| 751 |
+
"loss": 2.6146,
|
| 752 |
+
"step": 530
|
| 753 |
+
},
|
| 754 |
+
{
|
| 755 |
+
"epoch": 0.7234617985125085,
|
| 756 |
+
"grad_norm": 2.8423595428466797,
|
| 757 |
+
"learning_rate": 8.883356466135231e-06,
|
| 758 |
+
"loss": 2.6213,
|
| 759 |
+
"step": 535
|
| 760 |
+
},
|
| 761 |
+
{
|
| 762 |
+
"epoch": 0.7302231237322515,
|
| 763 |
+
"grad_norm": 2.929335594177246,
|
| 764 |
+
"learning_rate": 8.860274816344203e-06,
|
| 765 |
+
"loss": 2.6185,
|
| 766 |
+
"step": 540
|
| 767 |
+
},
|
| 768 |
+
{
|
| 769 |
+
"epoch": 0.7369844489519946,
|
| 770 |
+
"grad_norm": 2.9922103881835938,
|
| 771 |
+
"learning_rate": 8.836987687293868e-06,
|
| 772 |
+
"loss": 2.6042,
|
| 773 |
+
"step": 545
|
| 774 |
+
},
|
| 775 |
+
{
|
| 776 |
+
"epoch": 0.7437457741717377,
|
| 777 |
+
"grad_norm": 3.488055467605591,
|
| 778 |
+
"learning_rate": 8.813496318538985e-06,
|
| 779 |
+
"loss": 2.6443,
|
| 780 |
+
"step": 550
|
| 781 |
+
},
|
| 782 |
+
{
|
| 783 |
+
"epoch": 0.7505070993914807,
|
| 784 |
+
"grad_norm": 7.2074785232543945,
|
| 785 |
+
"learning_rate": 8.789801960505826e-06,
|
| 786 |
+
"loss": 2.6226,
|
| 787 |
+
"step": 555
|
| 788 |
+
},
|
| 789 |
+
{
|
| 790 |
+
"epoch": 0.7572684246112238,
|
| 791 |
+
"grad_norm": 3.040048360824585,
|
| 792 |
+
"learning_rate": 8.765905874425622e-06,
|
| 793 |
+
"loss": 2.6449,
|
| 794 |
+
"step": 560
|
| 795 |
+
},
|
| 796 |
+
{
|
| 797 |
+
"epoch": 0.7640297498309668,
|
| 798 |
+
"grad_norm": 2.8889758586883545,
|
| 799 |
+
"learning_rate": 8.741809332267413e-06,
|
| 800 |
+
"loss": 2.6391,
|
| 801 |
+
"step": 565
|
| 802 |
+
},
|
| 803 |
+
{
|
| 804 |
+
"epoch": 0.77079107505071,
|
| 805 |
+
"grad_norm": 3.0062615871429443,
|
| 806 |
+
"learning_rate": 8.717513616670357e-06,
|
| 807 |
+
"loss": 2.6383,
|
| 808 |
+
"step": 570
|
| 809 |
+
},
|
| 810 |
+
{
|
| 811 |
+
"epoch": 0.777552400270453,
|
| 812 |
+
"grad_norm": 2.8223934173583984,
|
| 813 |
+
"learning_rate": 8.693020020875448e-06,
|
| 814 |
+
"loss": 2.611,
|
| 815 |
+
"step": 575
|
| 816 |
+
},
|
| 817 |
+
{
|
| 818 |
+
"epoch": 0.7843137254901961,
|
| 819 |
+
"grad_norm": 2.990478754043579,
|
| 820 |
+
"learning_rate": 8.668329848656683e-06,
|
| 821 |
+
"loss": 2.6141,
|
| 822 |
+
"step": 580
|
| 823 |
+
},
|
| 824 |
+
{
|
| 825 |
+
"epoch": 0.7910750507099391,
|
| 826 |
+
"grad_norm": 2.6774513721466064,
|
| 827 |
+
"learning_rate": 8.643444414251659e-06,
|
| 828 |
+
"loss": 2.6101,
|
| 829 |
+
"step": 585
|
| 830 |
+
},
|
| 831 |
+
{
|
| 832 |
+
"epoch": 0.7978363759296823,
|
| 833 |
+
"grad_norm": 2.859231472015381,
|
| 834 |
+
"learning_rate": 8.61836504229162e-06,
|
| 835 |
+
"loss": 2.612,
|
| 836 |
+
"step": 590
|
| 837 |
+
},
|
| 838 |
+
{
|
| 839 |
+
"epoch": 0.8045977011494253,
|
| 840 |
+
"grad_norm": 4.325037479400635,
|
| 841 |
+
"learning_rate": 8.593093067730941e-06,
|
| 842 |
+
"loss": 2.6328,
|
| 843 |
+
"step": 595
|
| 844 |
+
},
|
| 845 |
+
{
|
| 846 |
+
"epoch": 0.8113590263691683,
|
| 847 |
+
"grad_norm": 2.8452208042144775,
|
| 848 |
+
"learning_rate": 8.56762983577609e-06,
|
| 849 |
+
"loss": 2.6006,
|
| 850 |
+
"step": 600
|
| 851 |
+
},
|
| 852 |
+
{
|
| 853 |
+
"epoch": 0.8181203515889114,
|
| 854 |
+
"grad_norm": 3.683469772338867,
|
| 855 |
+
"learning_rate": 8.54197670181399e-06,
|
| 856 |
+
"loss": 2.6527,
|
| 857 |
+
"step": 605
|
| 858 |
+
},
|
| 859 |
+
{
|
| 860 |
+
"epoch": 0.8248816768086545,
|
| 861 |
+
"grad_norm": 3.5392167568206787,
|
| 862 |
+
"learning_rate": 8.516135031339908e-06,
|
| 863 |
+
"loss": 2.6207,
|
| 864 |
+
"step": 610
|
| 865 |
+
},
|
| 866 |
+
{
|
| 867 |
+
"epoch": 0.8316430020283976,
|
| 868 |
+
"grad_norm": 2.7016098499298096,
|
| 869 |
+
"learning_rate": 8.490106199884742e-06,
|
| 870 |
+
"loss": 2.6212,
|
| 871 |
+
"step": 615
|
| 872 |
+
},
|
| 873 |
+
{
|
| 874 |
+
"epoch": 0.8384043272481406,
|
| 875 |
+
"grad_norm": 3.4844460487365723,
|
| 876 |
+
"learning_rate": 8.463891592941827e-06,
|
| 877 |
+
"loss": 2.6115,
|
| 878 |
+
"step": 620
|
| 879 |
+
},
|
| 880 |
+
{
|
| 881 |
+
"epoch": 0.8451656524678837,
|
| 882 |
+
"grad_norm": 2.874047040939331,
|
| 883 |
+
"learning_rate": 8.437492605893167e-06,
|
| 884 |
+
"loss": 2.5725,
|
| 885 |
+
"step": 625
|
| 886 |
+
},
|
| 887 |
+
{
|
| 888 |
+
"epoch": 0.8519269776876268,
|
| 889 |
+
"grad_norm": 3.063899040222168,
|
| 890 |
+
"learning_rate": 8.41091064393517e-06,
|
| 891 |
+
"loss": 2.6075,
|
| 892 |
+
"step": 630
|
| 893 |
+
},
|
| 894 |
+
{
|
| 895 |
+
"epoch": 0.8586883029073699,
|
| 896 |
+
"grad_norm": 2.8391199111938477,
|
| 897 |
+
"learning_rate": 8.38414712200385e-06,
|
| 898 |
+
"loss": 2.6123,
|
| 899 |
+
"step": 635
|
| 900 |
+
},
|
| 901 |
+
{
|
| 902 |
+
"epoch": 0.8654496281271129,
|
| 903 |
+
"grad_norm": 3.388949394226074,
|
| 904 |
+
"learning_rate": 8.357203464699502e-06,
|
| 905 |
+
"loss": 2.5755,
|
| 906 |
+
"step": 640
|
| 907 |
+
},
|
| 908 |
+
{
|
| 909 |
+
"epoch": 0.8722109533468559,
|
| 910 |
+
"grad_norm": 3.038212776184082,
|
| 911 |
+
"learning_rate": 8.330081106210889e-06,
|
| 912 |
+
"loss": 2.6086,
|
| 913 |
+
"step": 645
|
| 914 |
+
},
|
| 915 |
+
{
|
| 916 |
+
"epoch": 0.8789722785665991,
|
| 917 |
+
"grad_norm": 4.426064968109131,
|
| 918 |
+
"learning_rate": 8.302781490238888e-06,
|
| 919 |
+
"loss": 2.5918,
|
| 920 |
+
"step": 650
|
| 921 |
+
},
|
| 922 |
+
{
|
| 923 |
+
"epoch": 0.8857336037863421,
|
| 924 |
+
"grad_norm": 2.6291635036468506,
|
| 925 |
+
"learning_rate": 8.275306069919639e-06,
|
| 926 |
+
"loss": 2.5939,
|
| 927 |
+
"step": 655
|
| 928 |
+
},
|
| 929 |
+
{
|
| 930 |
+
"epoch": 0.8924949290060852,
|
| 931 |
+
"grad_norm": 2.598675489425659,
|
| 932 |
+
"learning_rate": 8.247656307747214e-06,
|
| 933 |
+
"loss": 2.5961,
|
| 934 |
+
"step": 660
|
| 935 |
+
},
|
| 936 |
+
{
|
| 937 |
+
"epoch": 0.8992562542258282,
|
| 938 |
+
"grad_norm": 2.9545516967773438,
|
| 939 |
+
"learning_rate": 8.219833675495754e-06,
|
| 940 |
+
"loss": 2.5854,
|
| 941 |
+
"step": 665
|
| 942 |
+
},
|
| 943 |
+
{
|
| 944 |
+
"epoch": 0.9060175794455714,
|
| 945 |
+
"grad_norm": 3.168442726135254,
|
| 946 |
+
"learning_rate": 8.19183965414113e-06,
|
| 947 |
+
"loss": 2.5691,
|
| 948 |
+
"step": 670
|
| 949 |
+
},
|
| 950 |
+
{
|
| 951 |
+
"epoch": 0.9127789046653144,
|
| 952 |
+
"grad_norm": 2.742135763168335,
|
| 953 |
+
"learning_rate": 8.163675733782114e-06,
|
| 954 |
+
"loss": 2.5574,
|
| 955 |
+
"step": 675
|
| 956 |
+
},
|
| 957 |
+
{
|
| 958 |
+
"epoch": 0.9195402298850575,
|
| 959 |
+
"grad_norm": 2.5857961177825928,
|
| 960 |
+
"learning_rate": 8.135343413561073e-06,
|
| 961 |
+
"loss": 2.591,
|
| 962 |
+
"step": 680
|
| 963 |
+
},
|
| 964 |
+
{
|
| 965 |
+
"epoch": 0.9263015551048005,
|
| 966 |
+
"grad_norm": 2.525702714920044,
|
| 967 |
+
"learning_rate": 8.106844201584145e-06,
|
| 968 |
+
"loss": 2.5952,
|
| 969 |
+
"step": 685
|
| 970 |
+
},
|
| 971 |
+
{
|
| 972 |
+
"epoch": 0.9330628803245437,
|
| 973 |
+
"grad_norm": 4.6076860427856445,
|
| 974 |
+
"learning_rate": 8.07817961484099e-06,
|
| 975 |
+
"loss": 2.5904,
|
| 976 |
+
"step": 690
|
| 977 |
+
},
|
| 978 |
+
{
|
| 979 |
+
"epoch": 0.9398242055442867,
|
| 980 |
+
"grad_norm": 4.223016738891602,
|
| 981 |
+
"learning_rate": 8.049351179124028e-06,
|
| 982 |
+
"loss": 2.5729,
|
| 983 |
+
"step": 695
|
| 984 |
+
},
|
| 985 |
+
{
|
| 986 |
+
"epoch": 0.9465855307640297,
|
| 987 |
+
"grad_norm": 3.6000704765319824,
|
| 988 |
+
"learning_rate": 8.020360428947223e-06,
|
| 989 |
+
"loss": 2.577,
|
| 990 |
+
"step": 700
|
| 991 |
+
},
|
| 992 |
+
{
|
| 993 |
+
"epoch": 0.9533468559837728,
|
| 994 |
+
"grad_norm": 2.7744557857513428,
|
| 995 |
+
"learning_rate": 7.991208907464405e-06,
|
| 996 |
+
"loss": 2.6169,
|
| 997 |
+
"step": 705
|
| 998 |
+
},
|
| 999 |
+
{
|
| 1000 |
+
"epoch": 0.9601081812035159,
|
| 1001 |
+
"grad_norm": 2.9555327892303467,
|
| 1002 |
+
"learning_rate": 7.961898166387136e-06,
|
| 1003 |
+
"loss": 2.5857,
|
| 1004 |
+
"step": 710
|
| 1005 |
+
},
|
| 1006 |
+
{
|
| 1007 |
+
"epoch": 0.966869506423259,
|
| 1008 |
+
"grad_norm": 3.189509153366089,
|
| 1009 |
+
"learning_rate": 7.932429765902095e-06,
|
| 1010 |
+
"loss": 2.5515,
|
| 1011 |
+
"step": 715
|
| 1012 |
+
},
|
| 1013 |
+
{
|
| 1014 |
+
"epoch": 0.973630831643002,
|
| 1015 |
+
"grad_norm": 3.0023581981658936,
|
| 1016 |
+
"learning_rate": 7.902805274588048e-06,
|
| 1017 |
+
"loss": 2.5478,
|
| 1018 |
+
"step": 720
|
| 1019 |
+
},
|
| 1020 |
+
{
|
| 1021 |
+
"epoch": 0.9803921568627451,
|
| 1022 |
+
"grad_norm": 2.8606345653533936,
|
| 1023 |
+
"learning_rate": 7.873026269332349e-06,
|
| 1024 |
+
"loss": 2.5681,
|
| 1025 |
+
"step": 725
|
| 1026 |
+
},
|
| 1027 |
+
{
|
| 1028 |
+
"epoch": 0.9871534820824882,
|
| 1029 |
+
"grad_norm": 3.11521053314209,
|
| 1030 |
+
"learning_rate": 7.843094335246997e-06,
|
| 1031 |
+
"loss": 2.5664,
|
| 1032 |
+
"step": 730
|
| 1033 |
+
},
|
| 1034 |
+
{
|
| 1035 |
+
"epoch": 0.9939148073022313,
|
| 1036 |
+
"grad_norm": 2.513296604156494,
|
| 1037 |
+
"learning_rate": 7.813011065584273e-06,
|
| 1038 |
+
"loss": 2.5622,
|
| 1039 |
+
"step": 735
|
| 1040 |
+
},
|
| 1041 |
+
{
|
| 1042 |
+
"epoch": 1.0,
|
| 1043 |
+
"grad_norm": 2.6706948280334473,
|
| 1044 |
+
"learning_rate": 7.782778061651922e-06,
|
| 1045 |
+
"loss": 2.3027,
|
| 1046 |
+
"step": 740
|
| 1047 |
+
},
|
| 1048 |
+
{
|
| 1049 |
+
"epoch": 1.0067613252197432,
|
| 1050 |
+
"grad_norm": 2.6789958477020264,
|
| 1051 |
+
"learning_rate": 7.752396932727926e-06,
|
| 1052 |
+
"loss": 2.5502,
|
| 1053 |
+
"step": 745
|
| 1054 |
+
},
|
| 1055 |
+
{
|
| 1056 |
+
"epoch": 1.013522650439486,
|
| 1057 |
+
"grad_norm": 2.6674933433532715,
|
| 1058 |
+
"learning_rate": 7.721869295974831e-06,
|
| 1059 |
+
"loss": 2.5365,
|
| 1060 |
+
"step": 750
|
| 1061 |
+
},
|
| 1062 |
+
{
|
| 1063 |
+
"epoch": 1.0202839756592292,
|
| 1064 |
+
"grad_norm": 2.80924654006958,
|
| 1065 |
+
"learning_rate": 7.691196776353681e-06,
|
| 1066 |
+
"loss": 2.4935,
|
| 1067 |
+
"step": 755
|
| 1068 |
+
},
|
| 1069 |
+
{
|
| 1070 |
+
"epoch": 1.0270453008789722,
|
| 1071 |
+
"grad_norm": 2.9341821670532227,
|
| 1072 |
+
"learning_rate": 7.660381006537516e-06,
|
| 1073 |
+
"loss": 2.548,
|
| 1074 |
+
"step": 760
|
| 1075 |
+
},
|
| 1076 |
+
{
|
| 1077 |
+
"epoch": 1.0338066260987153,
|
| 1078 |
+
"grad_norm": 2.9331564903259277,
|
| 1079 |
+
"learning_rate": 7.629423626824462e-06,
|
| 1080 |
+
"loss": 2.5119,
|
| 1081 |
+
"step": 765
|
| 1082 |
+
},
|
| 1083 |
+
{
|
| 1084 |
+
"epoch": 1.0405679513184585,
|
| 1085 |
+
"grad_norm": 3.1369872093200684,
|
| 1086 |
+
"learning_rate": 7.598326285050429e-06,
|
| 1087 |
+
"loss": 2.5118,
|
| 1088 |
+
"step": 770
|
| 1089 |
+
},
|
| 1090 |
+
{
|
| 1091 |
+
"epoch": 1.0473292765382014,
|
| 1092 |
+
"grad_norm": 3.999962329864502,
|
| 1093 |
+
"learning_rate": 7.567090636501386e-06,
|
| 1094 |
+
"loss": 2.555,
|
| 1095 |
+
"step": 775
|
| 1096 |
+
},
|
| 1097 |
+
{
|
| 1098 |
+
"epoch": 1.0540906017579446,
|
| 1099 |
+
"grad_norm": 2.822645902633667,
|
| 1100 |
+
"learning_rate": 7.535718343825267e-06,
|
| 1101 |
+
"loss": 2.5165,
|
| 1102 |
+
"step": 780
|
| 1103 |
+
},
|
| 1104 |
+
{
|
| 1105 |
+
"epoch": 1.0608519269776877,
|
| 1106 |
+
"grad_norm": 2.6943705081939697,
|
| 1107 |
+
"learning_rate": 7.504211076943448e-06,
|
| 1108 |
+
"loss": 2.485,
|
| 1109 |
+
"step": 785
|
| 1110 |
+
},
|
| 1111 |
+
{
|
| 1112 |
+
"epoch": 1.0676132521974306,
|
| 1113 |
+
"grad_norm": 2.860985040664673,
|
| 1114 |
+
"learning_rate": 7.4725705129618855e-06,
|
| 1115 |
+
"loss": 2.5193,
|
| 1116 |
+
"step": 790
|
| 1117 |
+
},
|
| 1118 |
+
{
|
| 1119 |
+
"epoch": 1.0743745774171738,
|
| 1120 |
+
"grad_norm": 2.7031378746032715,
|
| 1121 |
+
"learning_rate": 7.440798336081821e-06,
|
| 1122 |
+
"loss": 2.511,
|
| 1123 |
+
"step": 795
|
| 1124 |
+
},
|
| 1125 |
+
{
|
| 1126 |
+
"epoch": 1.081135902636917,
|
| 1127 |
+
"grad_norm": 3.222702741622925,
|
| 1128 |
+
"learning_rate": 7.408896237510146e-06,
|
| 1129 |
+
"loss": 2.5307,
|
| 1130 |
+
"step": 800
|
| 1131 |
+
},
|
| 1132 |
+
{
|
| 1133 |
+
"epoch": 1.0878972278566599,
|
| 1134 |
+
"grad_norm": 3.502304792404175,
|
| 1135 |
+
"learning_rate": 7.376865915369378e-06,
|
| 1136 |
+
"loss": 2.5419,
|
| 1137 |
+
"step": 805
|
| 1138 |
+
},
|
| 1139 |
+
{
|
| 1140 |
+
"epoch": 1.094658553076403,
|
| 1141 |
+
"grad_norm": 2.73856520652771,
|
| 1142 |
+
"learning_rate": 7.3447090746072666e-06,
|
| 1143 |
+
"loss": 2.5162,
|
| 1144 |
+
"step": 810
|
| 1145 |
+
},
|
| 1146 |
+
{
|
| 1147 |
+
"epoch": 1.101419878296146,
|
| 1148 |
+
"grad_norm": 2.9833099842071533,
|
| 1149 |
+
"learning_rate": 7.312427426906048e-06,
|
| 1150 |
+
"loss": 2.5051,
|
| 1151 |
+
"step": 815
|
| 1152 |
+
},
|
| 1153 |
+
{
|
| 1154 |
+
"epoch": 1.1081812035158891,
|
| 1155 |
+
"grad_norm": 3.2921409606933594,
|
| 1156 |
+
"learning_rate": 7.280022690591326e-06,
|
| 1157 |
+
"loss": 2.5362,
|
| 1158 |
+
"step": 820
|
| 1159 |
+
},
|
| 1160 |
+
{
|
| 1161 |
+
"epoch": 1.1149425287356323,
|
| 1162 |
+
"grad_norm": 3.6853201389312744,
|
| 1163 |
+
"learning_rate": 7.247496590540612e-06,
|
| 1164 |
+
"loss": 2.4959,
|
| 1165 |
+
"step": 825
|
| 1166 |
+
},
|
| 1167 |
+
{
|
| 1168 |
+
"epoch": 1.1217038539553752,
|
| 1169 |
+
"grad_norm": 3.182521343231201,
|
| 1170 |
+
"learning_rate": 7.214850858091509e-06,
|
| 1171 |
+
"loss": 2.4962,
|
| 1172 |
+
"step": 830
|
| 1173 |
+
},
|
| 1174 |
+
{
|
| 1175 |
+
"epoch": 1.1284651791751183,
|
| 1176 |
+
"grad_norm": 6.297270774841309,
|
| 1177 |
+
"learning_rate": 7.1820872309495534e-06,
|
| 1178 |
+
"loss": 2.5281,
|
| 1179 |
+
"step": 835
|
| 1180 |
+
},
|
| 1181 |
+
{
|
| 1182 |
+
"epoch": 1.1352265043948613,
|
| 1183 |
+
"grad_norm": 3.743927240371704,
|
| 1184 |
+
"learning_rate": 7.14920745309572e-06,
|
| 1185 |
+
"loss": 2.5215,
|
| 1186 |
+
"step": 840
|
| 1187 |
+
},
|
| 1188 |
+
{
|
| 1189 |
+
"epoch": 1.1419878296146044,
|
| 1190 |
+
"grad_norm": 2.9408071041107178,
|
| 1191 |
+
"learning_rate": 7.116213274693591e-06,
|
| 1192 |
+
"loss": 2.4759,
|
| 1193 |
+
"step": 845
|
| 1194 |
+
},
|
| 1195 |
+
{
|
| 1196 |
+
"epoch": 1.1487491548343476,
|
| 1197 |
+
"grad_norm": 2.461620330810547,
|
| 1198 |
+
"learning_rate": 7.083106451996194e-06,
|
| 1199 |
+
"loss": 2.545,
|
| 1200 |
+
"step": 850
|
| 1201 |
+
},
|
| 1202 |
+
{
|
| 1203 |
+
"epoch": 1.1555104800540905,
|
| 1204 |
+
"grad_norm": 3.0902323722839355,
|
| 1205 |
+
"learning_rate": 7.049888747252524e-06,
|
| 1206 |
+
"loss": 2.4778,
|
| 1207 |
+
"step": 855
|
| 1208 |
+
},
|
| 1209 |
+
{
|
| 1210 |
+
"epoch": 1.1622718052738337,
|
| 1211 |
+
"grad_norm": 2.803609848022461,
|
| 1212 |
+
"learning_rate": 7.016561928613733e-06,
|
| 1213 |
+
"loss": 2.4779,
|
| 1214 |
+
"step": 860
|
| 1215 |
+
},
|
| 1216 |
+
{
|
| 1217 |
+
"epoch": 1.1690331304935768,
|
| 1218 |
+
"grad_norm": 3.166276216506958,
|
| 1219 |
+
"learning_rate": 6.983127770039017e-06,
|
| 1220 |
+
"loss": 2.5279,
|
| 1221 |
+
"step": 865
|
| 1222 |
+
},
|
| 1223 |
+
{
|
| 1224 |
+
"epoch": 1.1757944557133198,
|
| 1225 |
+
"grad_norm": 3.0823771953582764,
|
| 1226 |
+
"learning_rate": 6.949588051201187e-06,
|
| 1227 |
+
"loss": 2.5216,
|
| 1228 |
+
"step": 870
|
| 1229 |
+
},
|
| 1230 |
+
{
|
| 1231 |
+
"epoch": 1.182555780933063,
|
| 1232 |
+
"grad_norm": 3.188164472579956,
|
| 1233 |
+
"learning_rate": 6.915944557391942e-06,
|
| 1234 |
+
"loss": 2.5035,
|
| 1235 |
+
"step": 875
|
| 1236 |
+
},
|
| 1237 |
+
{
|
| 1238 |
+
"epoch": 1.189317106152806,
|
| 1239 |
+
"grad_norm": 2.577242612838745,
|
| 1240 |
+
"learning_rate": 6.882199079426842e-06,
|
| 1241 |
+
"loss": 2.4836,
|
| 1242 |
+
"step": 880
|
| 1243 |
+
},
|
| 1244 |
+
{
|
| 1245 |
+
"epoch": 1.196078431372549,
|
| 1246 |
+
"grad_norm": 2.9939839839935303,
|
| 1247 |
+
"learning_rate": 6.8483534135499665e-06,
|
| 1248 |
+
"loss": 2.5142,
|
| 1249 |
+
"step": 885
|
| 1250 |
+
},
|
| 1251 |
+
{
|
| 1252 |
+
"epoch": 1.2028397565922921,
|
| 1253 |
+
"grad_norm": 2.834369421005249,
|
| 1254 |
+
"learning_rate": 6.814409361338331e-06,
|
| 1255 |
+
"loss": 2.5024,
|
| 1256 |
+
"step": 890
|
| 1257 |
+
},
|
| 1258 |
+
{
|
| 1259 |
+
"epoch": 1.209601081812035,
|
| 1260 |
+
"grad_norm": 2.8373208045959473,
|
| 1261 |
+
"learning_rate": 6.780368729605964e-06,
|
| 1262 |
+
"loss": 2.5255,
|
| 1263 |
+
"step": 895
|
| 1264 |
+
},
|
| 1265 |
+
{
|
| 1266 |
+
"epoch": 1.2163624070317782,
|
| 1267 |
+
"grad_norm": 3.0683062076568604,
|
| 1268 |
+
"learning_rate": 6.746233330307748e-06,
|
| 1269 |
+
"loss": 2.5038,
|
| 1270 |
+
"step": 900
|
| 1271 |
+
},
|
| 1272 |
+
{
|
| 1273 |
+
"epoch": 1.2231237322515214,
|
| 1274 |
+
"grad_norm": 2.5889170169830322,
|
| 1275 |
+
"learning_rate": 6.712004980442964e-06,
|
| 1276 |
+
"loss": 2.5026,
|
| 1277 |
+
"step": 905
|
| 1278 |
+
},
|
| 1279 |
+
{
|
| 1280 |
+
"epoch": 1.2298850574712643,
|
| 1281 |
+
"grad_norm": 3.1007654666900635,
|
| 1282 |
+
"learning_rate": 6.677685501958572e-06,
|
| 1283 |
+
"loss": 2.5123,
|
| 1284 |
+
"step": 910
|
| 1285 |
+
},
|
| 1286 |
+
{
|
| 1287 |
+
"epoch": 1.2366463826910075,
|
| 1288 |
+
"grad_norm": 2.7331902980804443,
|
| 1289 |
+
"learning_rate": 6.64327672165224e-06,
|
| 1290 |
+
"loss": 2.5092,
|
| 1291 |
+
"step": 915
|
| 1292 |
+
},
|
| 1293 |
+
{
|
| 1294 |
+
"epoch": 1.2434077079107504,
|
| 1295 |
+
"grad_norm": 2.818505048751831,
|
| 1296 |
+
"learning_rate": 6.608780471075092e-06,
|
| 1297 |
+
"loss": 2.4713,
|
| 1298 |
+
"step": 920
|
| 1299 |
+
},
|
| 1300 |
+
{
|
| 1301 |
+
"epoch": 1.2501690331304935,
|
| 1302 |
+
"grad_norm": 3.1065335273742676,
|
| 1303 |
+
"learning_rate": 6.574198586434229e-06,
|
| 1304 |
+
"loss": 2.519,
|
| 1305 |
+
"step": 925
|
| 1306 |
+
},
|
| 1307 |
+
{
|
| 1308 |
+
"epoch": 1.2569303583502367,
|
| 1309 |
+
"grad_norm": 3.60119366645813,
|
| 1310 |
+
"learning_rate": 6.5395329084949774e-06,
|
| 1311 |
+
"loss": 2.4981,
|
| 1312 |
+
"step": 930
|
| 1313 |
+
},
|
| 1314 |
+
{
|
| 1315 |
+
"epoch": 1.2636916835699799,
|
| 1316 |
+
"grad_norm": 2.812912702560425,
|
| 1317 |
+
"learning_rate": 6.504785282482917e-06,
|
| 1318 |
+
"loss": 2.5046,
|
| 1319 |
+
"step": 935
|
| 1320 |
+
},
|
| 1321 |
+
{
|
| 1322 |
+
"epoch": 1.2704530087897228,
|
| 1323 |
+
"grad_norm": 2.560412645339966,
|
| 1324 |
+
"learning_rate": 6.46995755798565e-06,
|
| 1325 |
+
"loss": 2.4667,
|
| 1326 |
+
"step": 940
|
| 1327 |
+
},
|
| 1328 |
+
{
|
| 1329 |
+
"epoch": 1.277214334009466,
|
| 1330 |
+
"grad_norm": 2.716543436050415,
|
| 1331 |
+
"learning_rate": 6.43505158885436e-06,
|
| 1332 |
+
"loss": 2.483,
|
| 1333 |
+
"step": 945
|
| 1334 |
+
},
|
| 1335 |
+
{
|
| 1336 |
+
"epoch": 1.2839756592292089,
|
| 1337 |
+
"grad_norm": 2.5889837741851807,
|
| 1338 |
+
"learning_rate": 6.400069233105132e-06,
|
| 1339 |
+
"loss": 2.474,
|
| 1340 |
+
"step": 950
|
| 1341 |
+
},
|
| 1342 |
+
{
|
| 1343 |
+
"epoch": 1.290736984448952,
|
| 1344 |
+
"grad_norm": 2.548285722732544,
|
| 1345 |
+
"learning_rate": 6.3650123528200354e-06,
|
| 1346 |
+
"loss": 2.4902,
|
| 1347 |
+
"step": 955
|
| 1348 |
+
},
|
| 1349 |
+
{
|
| 1350 |
+
"epoch": 1.2974983096686952,
|
| 1351 |
+
"grad_norm": 2.6211283206939697,
|
| 1352 |
+
"learning_rate": 6.3298828140480326e-06,
|
| 1353 |
+
"loss": 2.4542,
|
| 1354 |
+
"step": 960
|
| 1355 |
+
},
|
| 1356 |
+
{
|
| 1357 |
+
"epoch": 1.304259634888438,
|
| 1358 |
+
"grad_norm": 2.9109580516815186,
|
| 1359 |
+
"learning_rate": 6.29468248670563e-06,
|
| 1360 |
+
"loss": 2.4925,
|
| 1361 |
+
"step": 965
|
| 1362 |
+
},
|
| 1363 |
+
{
|
| 1364 |
+
"epoch": 1.3110209601081813,
|
| 1365 |
+
"grad_norm": 2.9635941982269287,
|
| 1366 |
+
"learning_rate": 6.259413244477355e-06,
|
| 1367 |
+
"loss": 2.4944,
|
| 1368 |
+
"step": 970
|
| 1369 |
+
},
|
| 1370 |
+
{
|
| 1371 |
+
"epoch": 1.3177822853279242,
|
| 1372 |
+
"grad_norm": 2.7843010425567627,
|
| 1373 |
+
"learning_rate": 6.224076964716015e-06,
|
| 1374 |
+
"loss": 2.4943,
|
| 1375 |
+
"step": 975
|
| 1376 |
+
},
|
| 1377 |
+
{
|
| 1378 |
+
"epoch": 1.3245436105476673,
|
| 1379 |
+
"grad_norm": 2.9173049926757812,
|
| 1380 |
+
"learning_rate": 6.188675528342772e-06,
|
| 1381 |
+
"loss": 2.4869,
|
| 1382 |
+
"step": 980
|
| 1383 |
+
},
|
| 1384 |
+
{
|
| 1385 |
+
"epoch": 1.3313049357674105,
|
| 1386 |
+
"grad_norm": 2.5200576782226562,
|
| 1387 |
+
"learning_rate": 6.153210819747022e-06,
|
| 1388 |
+
"loss": 2.4867,
|
| 1389 |
+
"step": 985
|
| 1390 |
+
},
|
| 1391 |
+
{
|
| 1392 |
+
"epoch": 1.3380662609871534,
|
| 1393 |
+
"grad_norm": 2.5795679092407227,
|
| 1394 |
+
"learning_rate": 6.117684726686086e-06,
|
| 1395 |
+
"loss": 2.5,
|
| 1396 |
+
"step": 990
|
| 1397 |
+
},
|
| 1398 |
+
{
|
| 1399 |
+
"epoch": 1.3448275862068966,
|
| 1400 |
+
"grad_norm": 2.6581368446350098,
|
| 1401 |
+
"learning_rate": 6.082099140184734e-06,
|
| 1402 |
+
"loss": 2.4833,
|
| 1403 |
+
"step": 995
|
| 1404 |
+
},
|
| 1405 |
+
{
|
| 1406 |
+
"epoch": 1.3515889114266395,
|
| 1407 |
+
"grad_norm": 3.1690869331359863,
|
| 1408 |
+
"learning_rate": 6.046455954434518e-06,
|
| 1409 |
+
"loss": 2.4825,
|
| 1410 |
+
"step": 1000
|
| 1411 |
+
},
|
| 1412 |
+
{
|
| 1413 |
+
"epoch": 1.3583502366463827,
|
| 1414 |
+
"grad_norm": 2.5110387802124023,
|
| 1415 |
+
"learning_rate": 6.010757066692957e-06,
|
| 1416 |
+
"loss": 2.4304,
|
| 1417 |
+
"step": 1005
|
| 1418 |
+
},
|
| 1419 |
+
{
|
| 1420 |
+
"epoch": 1.3651115618661258,
|
| 1421 |
+
"grad_norm": 3.335712194442749,
|
| 1422 |
+
"learning_rate": 5.975004377182536e-06,
|
| 1423 |
+
"loss": 2.477,
|
| 1424 |
+
"step": 1010
|
| 1425 |
+
},
|
| 1426 |
+
{
|
| 1427 |
+
"epoch": 1.371872887085869,
|
| 1428 |
+
"grad_norm": 2.6729347705841064,
|
| 1429 |
+
"learning_rate": 5.939199788989566e-06,
|
| 1430 |
+
"loss": 2.4795,
|
| 1431 |
+
"step": 1015
|
| 1432 |
+
},
|
| 1433 |
+
{
|
| 1434 |
+
"epoch": 1.378634212305612,
|
| 1435 |
+
"grad_norm": 3.0427603721618652,
|
| 1436 |
+
"learning_rate": 5.903345207962881e-06,
|
| 1437 |
+
"loss": 2.4701,
|
| 1438 |
+
"step": 1020
|
| 1439 |
+
},
|
| 1440 |
+
{
|
| 1441 |
+
"epoch": 1.385395537525355,
|
| 1442 |
+
"grad_norm": 3.156398057937622,
|
| 1443 |
+
"learning_rate": 5.867442542612394e-06,
|
| 1444 |
+
"loss": 2.4835,
|
| 1445 |
+
"step": 1025
|
| 1446 |
+
},
|
| 1447 |
+
{
|
| 1448 |
+
"epoch": 1.392156862745098,
|
| 1449 |
+
"grad_norm": 2.833634614944458,
|
| 1450 |
+
"learning_rate": 5.831493704007507e-06,
|
| 1451 |
+
"loss": 2.4716,
|
| 1452 |
+
"step": 1030
|
| 1453 |
+
},
|
| 1454 |
+
{
|
| 1455 |
+
"epoch": 1.3989181879648411,
|
| 1456 |
+
"grad_norm": 2.794393539428711,
|
| 1457 |
+
"learning_rate": 5.795500605675388e-06,
|
| 1458 |
+
"loss": 2.5017,
|
| 1459 |
+
"step": 1035
|
| 1460 |
+
},
|
| 1461 |
+
{
|
| 1462 |
+
"epoch": 1.4056795131845843,
|
| 1463 |
+
"grad_norm": 3.1075077056884766,
|
| 1464 |
+
"learning_rate": 5.7594651634991095e-06,
|
| 1465 |
+
"loss": 2.469,
|
| 1466 |
+
"step": 1040
|
| 1467 |
+
},
|
| 1468 |
+
{
|
| 1469 |
+
"epoch": 1.4124408384043272,
|
| 1470 |
+
"grad_norm": 2.718369483947754,
|
| 1471 |
+
"learning_rate": 5.723389295615676e-06,
|
| 1472 |
+
"loss": 2.4749,
|
| 1473 |
+
"step": 1045
|
| 1474 |
+
},
|
| 1475 |
+
{
|
| 1476 |
+
"epoch": 1.4192021636240704,
|
| 1477 |
+
"grad_norm": 2.5099501609802246,
|
| 1478 |
+
"learning_rate": 5.687274922313915e-06,
|
| 1479 |
+
"loss": 2.4739,
|
| 1480 |
+
"step": 1050
|
| 1481 |
+
},
|
| 1482 |
+
{
|
| 1483 |
+
"epoch": 1.4259634888438133,
|
| 1484 |
+
"grad_norm": 2.688002347946167,
|
| 1485 |
+
"learning_rate": 5.651123965932271e-06,
|
| 1486 |
+
"loss": 2.4275,
|
| 1487 |
+
"step": 1055
|
| 1488 |
+
},
|
| 1489 |
+
{
|
| 1490 |
+
"epoch": 1.4327248140635565,
|
| 1491 |
+
"grad_norm": 2.4511373043060303,
|
| 1492 |
+
"learning_rate": 5.614938350756475e-06,
|
| 1493 |
+
"loss": 2.4714,
|
| 1494 |
+
"step": 1060
|
| 1495 |
+
},
|
| 1496 |
+
{
|
| 1497 |
+
"epoch": 1.4394861392832996,
|
| 1498 |
+
"grad_norm": 2.583116054534912,
|
| 1499 |
+
"learning_rate": 5.5787200029171105e-06,
|
| 1500 |
+
"loss": 2.4539,
|
| 1501 |
+
"step": 1065
|
| 1502 |
+
},
|
| 1503 |
+
{
|
| 1504 |
+
"epoch": 1.4462474645030425,
|
| 1505 |
+
"grad_norm": 2.6514389514923096,
|
| 1506 |
+
"learning_rate": 5.542470850287105e-06,
|
| 1507 |
+
"loss": 2.4457,
|
| 1508 |
+
"step": 1070
|
| 1509 |
+
},
|
| 1510 |
+
{
|
| 1511 |
+
"epoch": 1.4530087897227857,
|
| 1512 |
+
"grad_norm": 2.9797661304473877,
|
| 1513 |
+
"learning_rate": 5.506192822379088e-06,
|
| 1514 |
+
"loss": 2.4713,
|
| 1515 |
+
"step": 1075
|
| 1516 |
+
},
|
| 1517 |
+
{
|
| 1518 |
+
"epoch": 1.4597701149425286,
|
| 1519 |
+
"grad_norm": 2.4024760723114014,
|
| 1520 |
+
"learning_rate": 5.469887850242707e-06,
|
| 1521 |
+
"loss": 2.4573,
|
| 1522 |
+
"step": 1080
|
| 1523 |
+
},
|
| 1524 |
+
{
|
| 1525 |
+
"epoch": 1.4665314401622718,
|
| 1526 |
+
"grad_norm": 5.054728031158447,
|
| 1527 |
+
"learning_rate": 5.433557866361818e-06,
|
| 1528 |
+
"loss": 2.4719,
|
| 1529 |
+
"step": 1085
|
| 1530 |
+
},
|
| 1531 |
+
{
|
| 1532 |
+
"epoch": 1.473292765382015,
|
| 1533 |
+
"grad_norm": 2.6720123291015625,
|
| 1534 |
+
"learning_rate": 5.397204804551642e-06,
|
| 1535 |
+
"loss": 2.4781,
|
| 1536 |
+
"step": 1090
|
| 1537 |
+
},
|
| 1538 |
+
{
|
| 1539 |
+
"epoch": 1.480054090601758,
|
| 1540 |
+
"grad_norm": 2.962134838104248,
|
| 1541 |
+
"learning_rate": 5.360830599855812e-06,
|
| 1542 |
+
"loss": 2.4477,
|
| 1543 |
+
"step": 1095
|
| 1544 |
+
},
|
| 1545 |
+
{
|
| 1546 |
+
"epoch": 1.486815415821501,
|
| 1547 |
+
"grad_norm": 2.5753014087677,
|
| 1548 |
+
"learning_rate": 5.324437188443381e-06,
|
| 1549 |
+
"loss": 2.447,
|
| 1550 |
+
"step": 1100
|
| 1551 |
+
},
|
| 1552 |
+
{
|
| 1553 |
+
"epoch": 1.4935767410412442,
|
| 1554 |
+
"grad_norm": 2.300673007965088,
|
| 1555 |
+
"learning_rate": 5.288026507505765e-06,
|
| 1556 |
+
"loss": 2.4847,
|
| 1557 |
+
"step": 1105
|
| 1558 |
+
},
|
| 1559 |
+
{
|
| 1560 |
+
"epoch": 1.500338066260987,
|
| 1561 |
+
"grad_norm": 2.465369701385498,
|
| 1562 |
+
"learning_rate": 5.2516004951536124e-06,
|
| 1563 |
+
"loss": 2.4708,
|
| 1564 |
+
"step": 1110
|
| 1565 |
+
},
|
| 1566 |
+
{
|
| 1567 |
+
"epoch": 1.5070993914807302,
|
| 1568 |
+
"grad_norm": 2.3910348415374756,
|
| 1569 |
+
"learning_rate": 5.21516109031366e-06,
|
| 1570 |
+
"loss": 2.4802,
|
| 1571 |
+
"step": 1115
|
| 1572 |
+
},
|
| 1573 |
+
{
|
| 1574 |
+
"epoch": 1.5138607167004734,
|
| 1575 |
+
"grad_norm": 3.5717501640319824,
|
| 1576 |
+
"learning_rate": 5.178710232625511e-06,
|
| 1577 |
+
"loss": 2.4703,
|
| 1578 |
+
"step": 1120
|
| 1579 |
+
},
|
| 1580 |
+
{
|
| 1581 |
+
"epoch": 1.5206220419202163,
|
| 1582 |
+
"grad_norm": 2.6131703853607178,
|
| 1583 |
+
"learning_rate": 5.142249862338395e-06,
|
| 1584 |
+
"loss": 2.4493,
|
| 1585 |
+
"step": 1125
|
| 1586 |
+
},
|
| 1587 |
+
{
|
| 1588 |
+
"epoch": 1.5273833671399595,
|
| 1589 |
+
"grad_norm": 2.7011117935180664,
|
| 1590 |
+
"learning_rate": 5.10578192020789e-06,
|
| 1591 |
+
"loss": 2.4647,
|
| 1592 |
+
"step": 1130
|
| 1593 |
+
},
|
| 1594 |
+
{
|
| 1595 |
+
"epoch": 1.5341446923597024,
|
| 1596 |
+
"grad_norm": 2.7816450595855713,
|
| 1597 |
+
"learning_rate": 5.069308347392614e-06,
|
| 1598 |
+
"loss": 2.4587,
|
| 1599 |
+
"step": 1135
|
| 1600 |
+
},
|
| 1601 |
+
{
|
| 1602 |
+
"epoch": 1.5409060175794456,
|
| 1603 |
+
"grad_norm": 3.070551633834839,
|
| 1604 |
+
"learning_rate": 5.0328310853509074e-06,
|
| 1605 |
+
"loss": 2.4518,
|
| 1606 |
+
"step": 1140
|
| 1607 |
+
},
|
| 1608 |
+
{
|
| 1609 |
+
"epoch": 1.5476673427991887,
|
| 1610 |
+
"grad_norm": 2.793508291244507,
|
| 1611 |
+
"learning_rate": 4.996352075737481e-06,
|
| 1612 |
+
"loss": 2.4641,
|
| 1613 |
+
"step": 1145
|
| 1614 |
+
},
|
| 1615 |
+
{
|
| 1616 |
+
"epoch": 1.5544286680189319,
|
| 1617 |
+
"grad_norm": 2.4779341220855713,
|
| 1618 |
+
"learning_rate": 4.95987326030007e-06,
|
| 1619 |
+
"loss": 2.4686,
|
| 1620 |
+
"step": 1150
|
| 1621 |
+
},
|
| 1622 |
+
{
|
| 1623 |
+
"epoch": 1.5611899932386748,
|
| 1624 |
+
"grad_norm": 3.4994513988494873,
|
| 1625 |
+
"learning_rate": 4.923396580776068e-06,
|
| 1626 |
+
"loss": 2.4357,
|
| 1627 |
+
"step": 1155
|
| 1628 |
+
},
|
| 1629 |
+
{
|
| 1630 |
+
"epoch": 1.5679513184584177,
|
| 1631 |
+
"grad_norm": 5.211581230163574,
|
| 1632 |
+
"learning_rate": 4.886923978789183e-06,
|
| 1633 |
+
"loss": 2.4893,
|
| 1634 |
+
"step": 1160
|
| 1635 |
+
},
|
| 1636 |
+
{
|
| 1637 |
+
"epoch": 1.5747126436781609,
|
| 1638 |
+
"grad_norm": 2.783217430114746,
|
| 1639 |
+
"learning_rate": 4.850457395746074e-06,
|
| 1640 |
+
"loss": 2.4364,
|
| 1641 |
+
"step": 1165
|
| 1642 |
+
},
|
| 1643 |
+
{
|
| 1644 |
+
"epoch": 1.581473968897904,
|
| 1645 |
+
"grad_norm": 2.6504037380218506,
|
| 1646 |
+
"learning_rate": 4.813998772733022e-06,
|
| 1647 |
+
"loss": 2.4823,
|
| 1648 |
+
"step": 1170
|
| 1649 |
+
},
|
| 1650 |
+
{
|
| 1651 |
+
"epoch": 1.5882352941176472,
|
| 1652 |
+
"grad_norm": 2.455275058746338,
|
| 1653 |
+
"learning_rate": 4.7775500504125945e-06,
|
| 1654 |
+
"loss": 2.4616,
|
| 1655 |
+
"step": 1175
|
| 1656 |
+
},
|
| 1657 |
+
{
|
| 1658 |
+
"epoch": 1.5949966193373901,
|
| 1659 |
+
"grad_norm": 2.9078075885772705,
|
| 1660 |
+
"learning_rate": 4.741113168920359e-06,
|
| 1661 |
+
"loss": 2.4495,
|
| 1662 |
+
"step": 1180
|
| 1663 |
+
},
|
| 1664 |
+
{
|
| 1665 |
+
"epoch": 1.601757944557133,
|
| 1666 |
+
"grad_norm": 3.3229355812072754,
|
| 1667 |
+
"learning_rate": 4.704690067761605e-06,
|
| 1668 |
+
"loss": 2.4375,
|
| 1669 |
+
"step": 1185
|
| 1670 |
+
},
|
| 1671 |
+
{
|
| 1672 |
+
"epoch": 1.6085192697768762,
|
| 1673 |
+
"grad_norm": 2.7873892784118652,
|
| 1674 |
+
"learning_rate": 4.668282685708102e-06,
|
| 1675 |
+
"loss": 2.4541,
|
| 1676 |
+
"step": 1190
|
| 1677 |
+
},
|
| 1678 |
+
{
|
| 1679 |
+
"epoch": 1.6152805949966194,
|
| 1680 |
+
"grad_norm": 2.7972123622894287,
|
| 1681 |
+
"learning_rate": 4.631892960694911e-06,
|
| 1682 |
+
"loss": 2.4567,
|
| 1683 |
+
"step": 1195
|
| 1684 |
+
},
|
| 1685 |
+
{
|
| 1686 |
+
"epoch": 1.6220419202163625,
|
| 1687 |
+
"grad_norm": 2.4656670093536377,
|
| 1688 |
+
"learning_rate": 4.595522829717217e-06,
|
| 1689 |
+
"loss": 2.4463,
|
| 1690 |
+
"step": 1200
|
| 1691 |
+
},
|
| 1692 |
+
{
|
| 1693 |
+
"epoch": 1.6288032454361054,
|
| 1694 |
+
"grad_norm": 3.0135202407836914,
|
| 1695 |
+
"learning_rate": 4.559174228727234e-06,
|
| 1696 |
+
"loss": 2.4437,
|
| 1697 |
+
"step": 1205
|
| 1698 |
+
},
|
| 1699 |
+
{
|
| 1700 |
+
"epoch": 1.6355645706558486,
|
| 1701 |
+
"grad_norm": 2.723539352416992,
|
| 1702 |
+
"learning_rate": 4.5228490925311506e-06,
|
| 1703 |
+
"loss": 2.4397,
|
| 1704 |
+
"step": 1210
|
| 1705 |
+
},
|
| 1706 |
+
{
|
| 1707 |
+
"epoch": 1.6423258958755915,
|
| 1708 |
+
"grad_norm": 2.662691354751587,
|
| 1709 |
+
"learning_rate": 4.486549354686148e-06,
|
| 1710 |
+
"loss": 2.4373,
|
| 1711 |
+
"step": 1215
|
| 1712 |
+
},
|
| 1713 |
+
{
|
| 1714 |
+
"epoch": 1.6490872210953347,
|
| 1715 |
+
"grad_norm": 2.6444590091705322,
|
| 1716 |
+
"learning_rate": 4.450276947397466e-06,
|
| 1717 |
+
"loss": 2.4563,
|
| 1718 |
+
"step": 1220
|
| 1719 |
+
},
|
| 1720 |
+
{
|
| 1721 |
+
"epoch": 1.6558485463150778,
|
| 1722 |
+
"grad_norm": 2.985874652862549,
|
| 1723 |
+
"learning_rate": 4.414033801415569e-06,
|
| 1724 |
+
"loss": 2.459,
|
| 1725 |
+
"step": 1225
|
| 1726 |
+
},
|
| 1727 |
+
{
|
| 1728 |
+
"epoch": 1.662609871534821,
|
| 1729 |
+
"grad_norm": 2.606755495071411,
|
| 1730 |
+
"learning_rate": 4.377821845933364e-06,
|
| 1731 |
+
"loss": 2.4403,
|
| 1732 |
+
"step": 1230
|
| 1733 |
+
},
|
| 1734 |
+
{
|
| 1735 |
+
"epoch": 1.669371196754564,
|
| 1736 |
+
"grad_norm": 2.5894505977630615,
|
| 1737 |
+
"learning_rate": 4.3416430084835095e-06,
|
| 1738 |
+
"loss": 2.4437,
|
| 1739 |
+
"step": 1235
|
| 1740 |
+
},
|
| 1741 |
+
{
|
| 1742 |
+
"epoch": 1.6761325219743068,
|
| 1743 |
+
"grad_norm": 2.9056777954101562,
|
| 1744 |
+
"learning_rate": 4.305499214835825e-06,
|
| 1745 |
+
"loss": 2.4335,
|
| 1746 |
+
"step": 1240
|
| 1747 |
+
},
|
| 1748 |
+
{
|
| 1749 |
+
"epoch": 1.68289384719405,
|
| 1750 |
+
"grad_norm": 2.6746933460235596,
|
| 1751 |
+
"learning_rate": 4.269392388894768e-06,
|
| 1752 |
+
"loss": 2.4317,
|
| 1753 |
+
"step": 1245
|
| 1754 |
+
},
|
| 1755 |
+
{
|
| 1756 |
+
"epoch": 1.6896551724137931,
|
| 1757 |
+
"grad_norm": 2.4791347980499268,
|
| 1758 |
+
"learning_rate": 4.233324452597046e-06,
|
| 1759 |
+
"loss": 2.4187,
|
| 1760 |
+
"step": 1250
|
| 1761 |
+
},
|
| 1762 |
+
{
|
| 1763 |
+
"epoch": 1.6964164976335363,
|
| 1764 |
+
"grad_norm": 2.4208455085754395,
|
| 1765 |
+
"learning_rate": 4.197297325809295e-06,
|
| 1766 |
+
"loss": 2.4328,
|
| 1767 |
+
"step": 1255
|
| 1768 |
+
},
|
| 1769 |
+
{
|
| 1770 |
+
"epoch": 1.7031778228532792,
|
| 1771 |
+
"grad_norm": 2.7689950466156006,
|
| 1772 |
+
"learning_rate": 4.161312926225898e-06,
|
| 1773 |
+
"loss": 2.4606,
|
| 1774 |
+
"step": 1260
|
| 1775 |
+
},
|
| 1776 |
+
{
|
| 1777 |
+
"epoch": 1.7099391480730222,
|
| 1778 |
+
"grad_norm": 2.2801952362060547,
|
| 1779 |
+
"learning_rate": 4.125373169266901e-06,
|
| 1780 |
+
"loss": 2.4256,
|
| 1781 |
+
"step": 1265
|
| 1782 |
+
},
|
| 1783 |
+
{
|
| 1784 |
+
"epoch": 1.7167004732927653,
|
| 1785 |
+
"grad_norm": 2.5390591621398926,
|
| 1786 |
+
"learning_rate": 4.089479967976063e-06,
|
| 1787 |
+
"loss": 2.407,
|
| 1788 |
+
"step": 1270
|
| 1789 |
+
},
|
| 1790 |
+
{
|
| 1791 |
+
"epoch": 1.7234617985125085,
|
| 1792 |
+
"grad_norm": 3.087167501449585,
|
| 1793 |
+
"learning_rate": 4.05363523291902e-06,
|
| 1794 |
+
"loss": 2.438,
|
| 1795 |
+
"step": 1275
|
| 1796 |
+
},
|
| 1797 |
+
{
|
| 1798 |
+
"epoch": 1.7302231237322516,
|
| 1799 |
+
"grad_norm": 2.693443775177002,
|
| 1800 |
+
"learning_rate": 4.017840872081593e-06,
|
| 1801 |
+
"loss": 2.4081,
|
| 1802 |
+
"step": 1280
|
| 1803 |
+
},
|
| 1804 |
+
{
|
| 1805 |
+
"epoch": 1.7369844489519946,
|
| 1806 |
+
"grad_norm": 2.6463053226470947,
|
| 1807 |
+
"learning_rate": 3.982098790768224e-06,
|
| 1808 |
+
"loss": 2.424,
|
| 1809 |
+
"step": 1285
|
| 1810 |
+
},
|
| 1811 |
+
{
|
| 1812 |
+
"epoch": 1.7437457741717377,
|
| 1813 |
+
"grad_norm": 2.368029832839966,
|
| 1814 |
+
"learning_rate": 3.946410891500556e-06,
|
| 1815 |
+
"loss": 2.4678,
|
| 1816 |
+
"step": 1290
|
| 1817 |
+
},
|
| 1818 |
+
{
|
| 1819 |
+
"epoch": 1.7505070993914806,
|
| 1820 |
+
"grad_norm": 2.3758246898651123,
|
| 1821 |
+
"learning_rate": 3.91077907391617e-06,
|
| 1822 |
+
"loss": 2.4215,
|
| 1823 |
+
"step": 1295
|
| 1824 |
+
},
|
| 1825 |
+
{
|
| 1826 |
+
"epoch": 1.7572684246112238,
|
| 1827 |
+
"grad_norm": 2.502300262451172,
|
| 1828 |
+
"learning_rate": 3.875205234667463e-06,
|
| 1829 |
+
"loss": 2.4178,
|
| 1830 |
+
"step": 1300
|
| 1831 |
+
},
|
| 1832 |
+
{
|
| 1833 |
+
"epoch": 1.764029749830967,
|
| 1834 |
+
"grad_norm": 3.306715250015259,
|
| 1835 |
+
"learning_rate": 3.839691267320693e-06,
|
| 1836 |
+
"loss": 2.429,
|
| 1837 |
+
"step": 1305
|
| 1838 |
+
},
|
| 1839 |
+
{
|
| 1840 |
+
"epoch": 1.77079107505071,
|
| 1841 |
+
"grad_norm": 2.5375657081604004,
|
| 1842 |
+
"learning_rate": 3.8042390622551856e-06,
|
| 1843 |
+
"loss": 2.4502,
|
| 1844 |
+
"step": 1310
|
| 1845 |
+
},
|
| 1846 |
+
{
|
| 1847 |
+
"epoch": 1.777552400270453,
|
| 1848 |
+
"grad_norm": 2.51631760597229,
|
| 1849 |
+
"learning_rate": 3.7688505065627114e-06,
|
| 1850 |
+
"loss": 2.4389,
|
| 1851 |
+
"step": 1315
|
| 1852 |
+
},
|
| 1853 |
+
{
|
| 1854 |
+
"epoch": 1.784313725490196,
|
| 1855 |
+
"grad_norm": 4.152524948120117,
|
| 1856 |
+
"learning_rate": 3.7335274839470394e-06,
|
| 1857 |
+
"loss": 2.425,
|
| 1858 |
+
"step": 1320
|
| 1859 |
+
},
|
| 1860 |
+
{
|
| 1861 |
+
"epoch": 1.791075050709939,
|
| 1862 |
+
"grad_norm": 2.4869284629821777,
|
| 1863 |
+
"learning_rate": 3.6982718746236603e-06,
|
| 1864 |
+
"loss": 2.4557,
|
| 1865 |
+
"step": 1325
|
| 1866 |
+
},
|
| 1867 |
+
{
|
| 1868 |
+
"epoch": 1.7978363759296823,
|
| 1869 |
+
"grad_norm": 2.5345115661621094,
|
| 1870 |
+
"learning_rate": 3.6630855552197177e-06,
|
| 1871 |
+
"loss": 2.4146,
|
| 1872 |
+
"step": 1330
|
| 1873 |
+
},
|
| 1874 |
+
{
|
| 1875 |
+
"epoch": 1.8045977011494254,
|
| 1876 |
+
"grad_norm": 2.511878490447998,
|
| 1877 |
+
"learning_rate": 3.627970398674104e-06,
|
| 1878 |
+
"loss": 2.4366,
|
| 1879 |
+
"step": 1335
|
| 1880 |
+
},
|
| 1881 |
+
{
|
| 1882 |
+
"epoch": 1.8113590263691683,
|
| 1883 |
+
"grad_norm": 2.6323208808898926,
|
| 1884 |
+
"learning_rate": 3.5929282741377773e-06,
|
| 1885 |
+
"loss": 2.4518,
|
| 1886 |
+
"step": 1340
|
| 1887 |
+
},
|
| 1888 |
+
{
|
| 1889 |
+
"epoch": 1.8181203515889113,
|
| 1890 |
+
"grad_norm": 2.635624885559082,
|
| 1891 |
+
"learning_rate": 3.557961046874255e-06,
|
| 1892 |
+
"loss": 2.4258,
|
| 1893 |
+
"step": 1345
|
| 1894 |
+
},
|
| 1895 |
+
{
|
| 1896 |
+
"epoch": 1.8248816768086544,
|
| 1897 |
+
"grad_norm": 2.3183505535125732,
|
| 1898 |
+
"learning_rate": 3.523070578160339e-06,
|
| 1899 |
+
"loss": 2.4306,
|
| 1900 |
+
"step": 1350
|
| 1901 |
+
},
|
| 1902 |
+
{
|
| 1903 |
+
"epoch": 1.8316430020283976,
|
| 1904 |
+
"grad_norm": 2.523566961288452,
|
| 1905 |
+
"learning_rate": 3.4882587251870336e-06,
|
| 1906 |
+
"loss": 2.4553,
|
| 1907 |
+
"step": 1355
|
| 1908 |
+
},
|
| 1909 |
+
{
|
| 1910 |
+
"epoch": 1.8384043272481407,
|
| 1911 |
+
"grad_norm": 2.98215651512146,
|
| 1912 |
+
"learning_rate": 3.4535273409606935e-06,
|
| 1913 |
+
"loss": 2.4179,
|
| 1914 |
+
"step": 1360
|
| 1915 |
+
},
|
| 1916 |
+
{
|
| 1917 |
+
"epoch": 1.8451656524678837,
|
| 1918 |
+
"grad_norm": 2.7971649169921875,
|
| 1919 |
+
"learning_rate": 3.4188782742043892e-06,
|
| 1920 |
+
"loss": 2.4225,
|
| 1921 |
+
"step": 1365
|
| 1922 |
+
},
|
| 1923 |
+
{
|
| 1924 |
+
"epoch": 1.8519269776876268,
|
| 1925 |
+
"grad_norm": 2.7544167041778564,
|
| 1926 |
+
"learning_rate": 3.3843133692594966e-06,
|
| 1927 |
+
"loss": 2.4076,
|
| 1928 |
+
"step": 1370
|
| 1929 |
+
},
|
| 1930 |
+
{
|
| 1931 |
+
"epoch": 1.8586883029073697,
|
| 1932 |
+
"grad_norm": 2.5221734046936035,
|
| 1933 |
+
"learning_rate": 3.3498344659875304e-06,
|
| 1934 |
+
"loss": 2.4144,
|
| 1935 |
+
"step": 1375
|
| 1936 |
+
},
|
| 1937 |
+
{
|
| 1938 |
+
"epoch": 1.865449628127113,
|
| 1939 |
+
"grad_norm": 2.2641069889068604,
|
| 1940 |
+
"learning_rate": 3.3154433996722037e-06,
|
| 1941 |
+
"loss": 2.4038,
|
| 1942 |
+
"step": 1380
|
| 1943 |
+
},
|
| 1944 |
+
{
|
| 1945 |
+
"epoch": 1.872210953346856,
|
| 1946 |
+
"grad_norm": 2.3761255741119385,
|
| 1947 |
+
"learning_rate": 3.281142000921745e-06,
|
| 1948 |
+
"loss": 2.4296,
|
| 1949 |
+
"step": 1385
|
| 1950 |
+
},
|
| 1951 |
+
{
|
| 1952 |
+
"epoch": 1.8789722785665992,
|
| 1953 |
+
"grad_norm": 2.4303650856018066,
|
| 1954 |
+
"learning_rate": 3.2469320955714472e-06,
|
| 1955 |
+
"loss": 2.3978,
|
| 1956 |
+
"step": 1390
|
| 1957 |
+
},
|
| 1958 |
+
{
|
| 1959 |
+
"epoch": 1.8857336037863421,
|
| 1960 |
+
"grad_norm": 3.042694091796875,
|
| 1961 |
+
"learning_rate": 3.2128155045864893e-06,
|
| 1962 |
+
"loss": 2.4117,
|
| 1963 |
+
"step": 1395
|
| 1964 |
+
},
|
| 1965 |
+
{
|
| 1966 |
+
"epoch": 1.892494929006085,
|
| 1967 |
+
"grad_norm": 2.3523356914520264,
|
| 1968 |
+
"learning_rate": 3.178794043964998e-06,
|
| 1969 |
+
"loss": 2.4145,
|
| 1970 |
+
"step": 1400
|
| 1971 |
+
},
|
| 1972 |
+
{
|
| 1973 |
+
"epoch": 1.8992562542258282,
|
| 1974 |
+
"grad_norm": 2.467633008956909,
|
| 1975 |
+
"learning_rate": 3.144869524641393e-06,
|
| 1976 |
+
"loss": 2.397,
|
| 1977 |
+
"step": 1405
|
| 1978 |
+
},
|
| 1979 |
+
{
|
| 1980 |
+
"epoch": 1.9060175794455714,
|
| 1981 |
+
"grad_norm": 2.5464890003204346,
|
| 1982 |
+
"learning_rate": 3.1110437523899874e-06,
|
| 1983 |
+
"loss": 2.4064,
|
| 1984 |
+
"step": 1410
|
| 1985 |
+
},
|
| 1986 |
+
{
|
| 1987 |
+
"epoch": 1.9127789046653145,
|
| 1988 |
+
"grad_norm": 2.362809658050537,
|
| 1989 |
+
"learning_rate": 3.077318527728867e-06,
|
| 1990 |
+
"loss": 2.4229,
|
| 1991 |
+
"step": 1415
|
| 1992 |
+
},
|
| 1993 |
+
{
|
| 1994 |
+
"epoch": 1.9195402298850575,
|
| 1995 |
+
"grad_norm": 2.8589625358581543,
|
| 1996 |
+
"learning_rate": 3.043695645824055e-06,
|
| 1997 |
+
"loss": 2.4406,
|
| 1998 |
+
"step": 1420
|
| 1999 |
+
},
|
| 2000 |
+
{
|
| 2001 |
+
"epoch": 1.9263015551048004,
|
| 2002 |
+
"grad_norm": 2.349301338195801,
|
| 2003 |
+
"learning_rate": 3.010176896393949e-06,
|
| 2004 |
+
"loss": 2.4243,
|
| 2005 |
+
"step": 1425
|
| 2006 |
+
},
|
| 2007 |
+
{
|
| 2008 |
+
"epoch": 1.9330628803245435,
|
| 2009 |
+
"grad_norm": 2.634345769882202,
|
| 2010 |
+
"learning_rate": 2.976764063614067e-06,
|
| 2011 |
+
"loss": 2.4362,
|
| 2012 |
+
"step": 1430
|
| 2013 |
+
},
|
| 2014 |
+
{
|
| 2015 |
+
"epoch": 1.9398242055442867,
|
| 2016 |
+
"grad_norm": 2.4867677688598633,
|
| 2017 |
+
"learning_rate": 2.9434589260220637e-06,
|
| 2018 |
+
"loss": 2.427,
|
| 2019 |
+
"step": 1435
|
| 2020 |
+
},
|
| 2021 |
+
{
|
| 2022 |
+
"epoch": 1.9465855307640298,
|
| 2023 |
+
"grad_norm": 5.755255699157715,
|
| 2024 |
+
"learning_rate": 2.9102632564230726e-06,
|
| 2025 |
+
"loss": 2.3987,
|
| 2026 |
+
"step": 1440
|
| 2027 |
+
},
|
| 2028 |
+
{
|
| 2029 |
+
"epoch": 1.9533468559837728,
|
| 2030 |
+
"grad_norm": 2.603665590286255,
|
| 2031 |
+
"learning_rate": 2.8771788217953333e-06,
|
| 2032 |
+
"loss": 2.4174,
|
| 2033 |
+
"step": 1445
|
| 2034 |
+
},
|
| 2035 |
+
{
|
| 2036 |
+
"epoch": 1.960108181203516,
|
| 2037 |
+
"grad_norm": 2.6414690017700195,
|
| 2038 |
+
"learning_rate": 2.844207383196137e-06,
|
| 2039 |
+
"loss": 2.4183,
|
| 2040 |
+
"step": 1450
|
| 2041 |
+
},
|
| 2042 |
+
{
|
| 2043 |
+
"epoch": 1.9668695064232589,
|
| 2044 |
+
"grad_norm": 2.567423105239868,
|
| 2045 |
+
"learning_rate": 2.811350695668097e-06,
|
| 2046 |
+
"loss": 2.4177,
|
| 2047 |
+
"step": 1455
|
| 2048 |
+
},
|
| 2049 |
+
{
|
| 2050 |
+
"epoch": 1.973630831643002,
|
| 2051 |
+
"grad_norm": 2.662747859954834,
|
| 2052 |
+
"learning_rate": 2.7786105081457138e-06,
|
| 2053 |
+
"loss": 2.4356,
|
| 2054 |
+
"step": 1460
|
| 2055 |
+
},
|
| 2056 |
+
{
|
| 2057 |
+
"epoch": 1.9803921568627452,
|
| 2058 |
+
"grad_norm": 2.4450554847717285,
|
| 2059 |
+
"learning_rate": 2.745988563362287e-06,
|
| 2060 |
+
"loss": 2.3956,
|
| 2061 |
+
"step": 1465
|
| 2062 |
+
},
|
| 2063 |
+
{
|
| 2064 |
+
"epoch": 1.9871534820824883,
|
| 2065 |
+
"grad_norm": 2.6526248455047607,
|
| 2066 |
+
"learning_rate": 2.7134865977571622e-06,
|
| 2067 |
+
"loss": 2.428,
|
| 2068 |
+
"step": 1470
|
| 2069 |
+
},
|
| 2070 |
+
{
|
| 2071 |
+
"epoch": 1.9939148073022313,
|
| 2072 |
+
"grad_norm": 2.8979547023773193,
|
| 2073 |
+
"learning_rate": 2.681106341383283e-06,
|
| 2074 |
+
"loss": 2.4408,
|
| 2075 |
+
"step": 1475
|
| 2076 |
+
},
|
| 2077 |
+
{
|
| 2078 |
+
"epoch": 2.0,
|
| 2079 |
+
"grad_norm": 2.4628653526306152,
|
| 2080 |
+
"learning_rate": 2.6488495178151107e-06,
|
| 2081 |
+
"loss": 2.2029,
|
| 2082 |
+
"step": 1480
|
| 2083 |
+
},
|
| 2084 |
+
{
|
| 2085 |
+
"epoch": 2.006761325219743,
|
| 2086 |
+
"grad_norm": 2.8820254802703857,
|
| 2087 |
+
"learning_rate": 2.616717844056882e-06,
|
| 2088 |
+
"loss": 2.394,
|
| 2089 |
+
"step": 1485
|
| 2090 |
+
},
|
| 2091 |
+
{
|
| 2092 |
+
"epoch": 2.0135226504394863,
|
| 2093 |
+
"grad_norm": 4.178656101226807,
|
| 2094 |
+
"learning_rate": 2.5847130304512158e-06,
|
| 2095 |
+
"loss": 2.4002,
|
| 2096 |
+
"step": 1490
|
| 2097 |
+
},
|
| 2098 |
+
{
|
| 2099 |
+
"epoch": 2.020283975659229,
|
| 2100 |
+
"grad_norm": 2.5161166191101074,
|
| 2101 |
+
"learning_rate": 2.5528367805880627e-06,
|
| 2102 |
+
"loss": 2.3765,
|
| 2103 |
+
"step": 1495
|
| 2104 |
+
},
|
| 2105 |
+
{
|
| 2106 |
+
"epoch": 2.027045300878972,
|
| 2107 |
+
"grad_norm": 2.4519433975219727,
|
| 2108 |
+
"learning_rate": 2.5210907912140326e-06,
|
| 2109 |
+
"loss": 2.4097,
|
| 2110 |
+
"step": 1500
|
| 2111 |
+
},
|
| 2112 |
+
{
|
| 2113 |
+
"epoch": 2.0338066260987153,
|
| 2114 |
+
"grad_norm": 2.246267795562744,
|
| 2115 |
+
"learning_rate": 2.4894767521420805e-06,
|
| 2116 |
+
"loss": 2.3988,
|
| 2117 |
+
"step": 1505
|
| 2118 |
+
},
|
| 2119 |
+
{
|
| 2120 |
+
"epoch": 2.0405679513184585,
|
| 2121 |
+
"grad_norm": 2.803452968597412,
|
| 2122 |
+
"learning_rate": 2.4579963461615496e-06,
|
| 2123 |
+
"loss": 2.4005,
|
| 2124 |
+
"step": 1510
|
| 2125 |
+
},
|
| 2126 |
+
{
|
| 2127 |
+
"epoch": 2.0473292765382016,
|
| 2128 |
+
"grad_norm": 3.4639711380004883,
|
| 2129 |
+
"learning_rate": 2.426651248948607e-06,
|
| 2130 |
+
"loss": 2.4229,
|
| 2131 |
+
"step": 1515
|
| 2132 |
+
},
|
| 2133 |
+
{
|
| 2134 |
+
"epoch": 2.0540906017579443,
|
| 2135 |
+
"grad_norm": 2.396606206893921,
|
| 2136 |
+
"learning_rate": 2.395443128977042e-06,
|
| 2137 |
+
"loss": 2.3826,
|
| 2138 |
+
"step": 1520
|
| 2139 |
+
},
|
| 2140 |
+
{
|
| 2141 |
+
"epoch": 2.0608519269776875,
|
| 2142 |
+
"grad_norm": 3.1604995727539062,
|
| 2143 |
+
"learning_rate": 2.3643736474294626e-06,
|
| 2144 |
+
"loss": 2.38,
|
| 2145 |
+
"step": 1525
|
| 2146 |
+
},
|
| 2147 |
+
{
|
| 2148 |
+
"epoch": 2.0676132521974306,
|
| 2149 |
+
"grad_norm": 5.628172397613525,
|
| 2150 |
+
"learning_rate": 2.3334444581088633e-06,
|
| 2151 |
+
"loss": 2.4044,
|
| 2152 |
+
"step": 1530
|
| 2153 |
+
},
|
| 2154 |
+
{
|
| 2155 |
+
"epoch": 2.074374577417174,
|
| 2156 |
+
"grad_norm": 2.5617904663085938,
|
| 2157 |
+
"learning_rate": 2.302657207350599e-06,
|
| 2158 |
+
"loss": 2.3835,
|
| 2159 |
+
"step": 1535
|
| 2160 |
+
},
|
| 2161 |
+
{
|
| 2162 |
+
"epoch": 2.081135902636917,
|
| 2163 |
+
"grad_norm": 2.4702658653259277,
|
| 2164 |
+
"learning_rate": 2.272013533934752e-06,
|
| 2165 |
+
"loss": 2.3919,
|
| 2166 |
+
"step": 1540
|
| 2167 |
+
},
|
| 2168 |
+
{
|
| 2169 |
+
"epoch": 2.08789722785666,
|
| 2170 |
+
"grad_norm": 2.327834129333496,
|
| 2171 |
+
"learning_rate": 2.241515068998903e-06,
|
| 2172 |
+
"loss": 2.383,
|
| 2173 |
+
"step": 1545
|
| 2174 |
+
},
|
| 2175 |
+
{
|
| 2176 |
+
"epoch": 2.094658553076403,
|
| 2177 |
+
"grad_norm": 2.5790200233459473,
|
| 2178 |
+
"learning_rate": 2.2111634359513007e-06,
|
| 2179 |
+
"loss": 2.3888,
|
| 2180 |
+
"step": 1550
|
| 2181 |
+
}
|
| 2182 |
+
],
|
| 2183 |
+
"logging_steps": 5,
|
| 2184 |
+
"max_steps": 2220,
|
| 2185 |
+
"num_input_tokens_seen": 0,
|
| 2186 |
+
"num_train_epochs": 3,
|
| 2187 |
+
"save_steps": 25,
|
| 2188 |
+
"stateful_callbacks": {
|
| 2189 |
+
"TrainerControl": {
|
| 2190 |
+
"args": {
|
| 2191 |
+
"should_epoch_stop": false,
|
| 2192 |
+
"should_evaluate": false,
|
| 2193 |
+
"should_log": false,
|
| 2194 |
+
"should_save": true,
|
| 2195 |
+
"should_training_stop": false
|
| 2196 |
+
},
|
| 2197 |
+
"attributes": {}
|
| 2198 |
+
}
|
| 2199 |
+
},
|
| 2200 |
+
"total_flos": 1.3720287815503394e+20,
|
| 2201 |
+
"train_batch_size": 32,
|
| 2202 |
+
"trial_name": null,
|
| 2203 |
+
"trial_params": null
|
| 2204 |
+
}
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dc1f054fb9418a96145fe6dc451e5844758ecb41d8154f513a240f7460914e81
|
| 3 |
+
size 7761
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
zero_to_fp32.py
ADDED
|
@@ -0,0 +1,760 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
|
| 3 |
+
# Copyright (c) Microsoft Corporation.
|
| 4 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
|
| 6 |
+
# DeepSpeed Team
|
| 7 |
+
|
| 8 |
+
# This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
|
| 9 |
+
# copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
|
| 10 |
+
# the future. Once extracted, the weights don't require DeepSpeed and can be used in any
|
| 11 |
+
# application.
|
| 12 |
+
#
|
| 13 |
+
# example:
|
| 14 |
+
# python zero_to_fp32.py . output_dir/
|
| 15 |
+
# or
|
| 16 |
+
# python zero_to_fp32.py . output_dir/ --safe_serialization
|
| 17 |
+
|
| 18 |
+
import argparse
|
| 19 |
+
import torch
|
| 20 |
+
import glob
|
| 21 |
+
import math
|
| 22 |
+
import os
|
| 23 |
+
import re
|
| 24 |
+
import gc
|
| 25 |
+
import json
|
| 26 |
+
import numpy as np
|
| 27 |
+
from tqdm import tqdm
|
| 28 |
+
from collections import OrderedDict
|
| 29 |
+
from dataclasses import dataclass
|
| 30 |
+
|
| 31 |
+
# while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
|
| 32 |
+
# DeepSpeed data structures it has to be available in the current python environment.
|
| 33 |
+
from deepspeed.utils import logger
|
| 34 |
+
from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
|
| 35 |
+
FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
|
| 36 |
+
FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
@dataclass
|
| 40 |
+
class zero_model_state:
|
| 41 |
+
buffers: dict()
|
| 42 |
+
param_shapes: dict()
|
| 43 |
+
shared_params: list
|
| 44 |
+
ds_version: int
|
| 45 |
+
frozen_param_shapes: dict()
|
| 46 |
+
frozen_param_fragments: dict()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
debug = 0
|
| 50 |
+
|
| 51 |
+
# load to cpu
|
| 52 |
+
device = torch.device('cpu')
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def atoi(text):
|
| 56 |
+
return int(text) if text.isdigit() else text
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def natural_keys(text):
|
| 60 |
+
'''
|
| 61 |
+
alist.sort(key=natural_keys) sorts in human order
|
| 62 |
+
http://nedbatchelder.com/blog/200712/human_sorting.html
|
| 63 |
+
(See Toothy's implementation in the comments)
|
| 64 |
+
'''
|
| 65 |
+
return [atoi(c) for c in re.split(r'(\d+)', text)]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def get_model_state_file(checkpoint_dir, zero_stage):
|
| 69 |
+
if not os.path.isdir(checkpoint_dir):
|
| 70 |
+
raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
|
| 71 |
+
|
| 72 |
+
# there should be only one file
|
| 73 |
+
if zero_stage <= 2:
|
| 74 |
+
file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
|
| 75 |
+
elif zero_stage == 3:
|
| 76 |
+
file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
|
| 77 |
+
|
| 78 |
+
if not os.path.exists(file):
|
| 79 |
+
raise FileNotFoundError(f"can't find model states file at '{file}'")
|
| 80 |
+
|
| 81 |
+
return file
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def get_checkpoint_files(checkpoint_dir, glob_pattern):
|
| 85 |
+
# XXX: need to test that this simple glob rule works for multi-node setup too
|
| 86 |
+
ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
|
| 87 |
+
|
| 88 |
+
if len(ckpt_files) == 0:
|
| 89 |
+
raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
|
| 90 |
+
|
| 91 |
+
return ckpt_files
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def get_optim_files(checkpoint_dir):
|
| 95 |
+
return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def get_model_state_files(checkpoint_dir):
|
| 99 |
+
return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def parse_model_states(files):
|
| 103 |
+
zero_model_states = []
|
| 104 |
+
for file in files:
|
| 105 |
+
state_dict = torch.load(file, map_location=device, weights_only=False)
|
| 106 |
+
|
| 107 |
+
if BUFFER_NAMES not in state_dict:
|
| 108 |
+
raise ValueError(f"{file} is not a model state checkpoint")
|
| 109 |
+
buffer_names = state_dict[BUFFER_NAMES]
|
| 110 |
+
if debug:
|
| 111 |
+
print("Found buffers:", buffer_names)
|
| 112 |
+
|
| 113 |
+
# recover just the buffers while restoring them to fp32 if they were saved in fp16
|
| 114 |
+
buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
|
| 115 |
+
param_shapes = state_dict[PARAM_SHAPES]
|
| 116 |
+
|
| 117 |
+
# collect parameters that are included in param_shapes
|
| 118 |
+
param_names = []
|
| 119 |
+
for s in param_shapes:
|
| 120 |
+
for name in s.keys():
|
| 121 |
+
param_names.append(name)
|
| 122 |
+
|
| 123 |
+
# update with frozen parameters
|
| 124 |
+
frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
|
| 125 |
+
if frozen_param_shapes is not None:
|
| 126 |
+
if debug:
|
| 127 |
+
print(f"Found frozen_param_shapes: {frozen_param_shapes}")
|
| 128 |
+
param_names += list(frozen_param_shapes.keys())
|
| 129 |
+
|
| 130 |
+
# handle shared params
|
| 131 |
+
shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
|
| 132 |
+
|
| 133 |
+
ds_version = state_dict.get(DS_VERSION, None)
|
| 134 |
+
|
| 135 |
+
frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
|
| 136 |
+
|
| 137 |
+
z_model_state = zero_model_state(buffers=buffers,
|
| 138 |
+
param_shapes=param_shapes,
|
| 139 |
+
shared_params=shared_params,
|
| 140 |
+
ds_version=ds_version,
|
| 141 |
+
frozen_param_shapes=frozen_param_shapes,
|
| 142 |
+
frozen_param_fragments=frozen_param_fragments)
|
| 143 |
+
zero_model_states.append(z_model_state)
|
| 144 |
+
|
| 145 |
+
return zero_model_states
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def parse_optim_states(files, ds_checkpoint_dir):
|
| 149 |
+
total_files = len(files)
|
| 150 |
+
state_dicts = []
|
| 151 |
+
for f in tqdm(files, desc='Loading checkpoint shards'):
|
| 152 |
+
state_dict = torch.load(f, map_location=device, mmap=True, weights_only=False)
|
| 153 |
+
# immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
|
| 154 |
+
# and also handle the case where it was already removed by another helper script
|
| 155 |
+
state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
|
| 156 |
+
state_dicts.append(state_dict)
|
| 157 |
+
|
| 158 |
+
if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
|
| 159 |
+
raise ValueError(f"{files[0]} is not a zero checkpoint")
|
| 160 |
+
zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
|
| 161 |
+
world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
|
| 162 |
+
|
| 163 |
+
# For ZeRO-2 each param group can have different partition_count as data parallelism for expert
|
| 164 |
+
# parameters can be different from data parallelism for non-expert parameters. So we can just
|
| 165 |
+
# use the max of the partition_count to get the dp world_size.
|
| 166 |
+
|
| 167 |
+
if type(world_size) is list:
|
| 168 |
+
world_size = max(world_size)
|
| 169 |
+
|
| 170 |
+
if world_size != total_files:
|
| 171 |
+
raise ValueError(
|
| 172 |
+
f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
|
| 173 |
+
"Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
# the groups are named differently in each stage
|
| 177 |
+
if zero_stage <= 2:
|
| 178 |
+
fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
|
| 179 |
+
elif zero_stage == 3:
|
| 180 |
+
fp32_groups_key = FP32_FLAT_GROUPS
|
| 181 |
+
else:
|
| 182 |
+
raise ValueError(f"unknown zero stage {zero_stage}")
|
| 183 |
+
|
| 184 |
+
fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
|
| 185 |
+
return zero_stage, world_size, fp32_flat_groups
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
|
| 189 |
+
"""
|
| 190 |
+
Returns fp32 state_dict reconstructed from ds checkpoint
|
| 191 |
+
|
| 192 |
+
Args:
|
| 193 |
+
- ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
|
| 194 |
+
|
| 195 |
+
"""
|
| 196 |
+
print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
|
| 197 |
+
|
| 198 |
+
optim_files = get_optim_files(ds_checkpoint_dir)
|
| 199 |
+
zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
|
| 200 |
+
print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
|
| 201 |
+
|
| 202 |
+
model_files = get_model_state_files(ds_checkpoint_dir)
|
| 203 |
+
|
| 204 |
+
zero_model_states = parse_model_states(model_files)
|
| 205 |
+
print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
|
| 206 |
+
|
| 207 |
+
if zero_stage <= 2:
|
| 208 |
+
return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 209 |
+
exclude_frozen_parameters)
|
| 210 |
+
elif zero_stage == 3:
|
| 211 |
+
return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 212 |
+
exclude_frozen_parameters)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def _zero2_merge_frozen_params(state_dict, zero_model_states):
|
| 216 |
+
if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
|
| 217 |
+
return
|
| 218 |
+
|
| 219 |
+
frozen_param_shapes = zero_model_states[0].frozen_param_shapes
|
| 220 |
+
frozen_param_fragments = zero_model_states[0].frozen_param_fragments
|
| 221 |
+
|
| 222 |
+
if debug:
|
| 223 |
+
num_elem = sum(s.numel() for s in frozen_param_shapes.values())
|
| 224 |
+
print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
|
| 225 |
+
|
| 226 |
+
wanted_params = len(frozen_param_shapes)
|
| 227 |
+
wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
|
| 228 |
+
avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
|
| 229 |
+
print(f'Frozen params: Have {avail_numel} numels to process.')
|
| 230 |
+
print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
|
| 231 |
+
|
| 232 |
+
total_params = 0
|
| 233 |
+
total_numel = 0
|
| 234 |
+
for name, shape in frozen_param_shapes.items():
|
| 235 |
+
total_params += 1
|
| 236 |
+
unpartitioned_numel = shape.numel()
|
| 237 |
+
total_numel += unpartitioned_numel
|
| 238 |
+
|
| 239 |
+
state_dict[name] = frozen_param_fragments[name]
|
| 240 |
+
|
| 241 |
+
if debug:
|
| 242 |
+
print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
|
| 243 |
+
|
| 244 |
+
print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _has_callable(obj, fn):
|
| 248 |
+
attr = getattr(obj, fn, None)
|
| 249 |
+
return callable(attr)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
|
| 253 |
+
param_shapes = zero_model_states[0].param_shapes
|
| 254 |
+
|
| 255 |
+
# Reconstruction protocol:
|
| 256 |
+
#
|
| 257 |
+
# XXX: document this
|
| 258 |
+
|
| 259 |
+
if debug:
|
| 260 |
+
for i in range(world_size):
|
| 261 |
+
for j in range(len(fp32_flat_groups[0])):
|
| 262 |
+
print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
|
| 263 |
+
|
| 264 |
+
# XXX: memory usage doubles here (zero2)
|
| 265 |
+
num_param_groups = len(fp32_flat_groups[0])
|
| 266 |
+
merged_single_partition_of_fp32_groups = []
|
| 267 |
+
for i in range(num_param_groups):
|
| 268 |
+
merged_partitions = [sd[i] for sd in fp32_flat_groups]
|
| 269 |
+
full_single_fp32_vector = torch.cat(merged_partitions, 0)
|
| 270 |
+
merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
|
| 271 |
+
avail_numel = sum(
|
| 272 |
+
[full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
|
| 273 |
+
|
| 274 |
+
if debug:
|
| 275 |
+
wanted_params = sum([len(shapes) for shapes in param_shapes])
|
| 276 |
+
wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
|
| 277 |
+
# not asserting if there is a mismatch due to possible padding
|
| 278 |
+
print(f"Have {avail_numel} numels to process.")
|
| 279 |
+
print(f"Need {wanted_numel} numels in {wanted_params} params.")
|
| 280 |
+
|
| 281 |
+
# params
|
| 282 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
| 283 |
+
# out-of-core computing solution
|
| 284 |
+
total_numel = 0
|
| 285 |
+
total_params = 0
|
| 286 |
+
for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
|
| 287 |
+
offset = 0
|
| 288 |
+
avail_numel = full_single_fp32_vector.numel()
|
| 289 |
+
for name, shape in shapes.items():
|
| 290 |
+
|
| 291 |
+
unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
|
| 292 |
+
total_numel += unpartitioned_numel
|
| 293 |
+
total_params += 1
|
| 294 |
+
|
| 295 |
+
if debug:
|
| 296 |
+
print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
|
| 297 |
+
state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
|
| 298 |
+
offset += unpartitioned_numel
|
| 299 |
+
|
| 300 |
+
# Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
|
| 301 |
+
# avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
|
| 302 |
+
# paddings performed in the code it's almost impossible to predict the exact numbers w/o the
|
| 303 |
+
# live optimizer object, so we are checking that the numbers are within the right range
|
| 304 |
+
align_to = 2 * world_size
|
| 305 |
+
|
| 306 |
+
def zero2_align(x):
|
| 307 |
+
return align_to * math.ceil(x / align_to)
|
| 308 |
+
|
| 309 |
+
if debug:
|
| 310 |
+
print(f"original offset={offset}, avail_numel={avail_numel}")
|
| 311 |
+
|
| 312 |
+
offset = zero2_align(offset)
|
| 313 |
+
avail_numel = zero2_align(avail_numel)
|
| 314 |
+
|
| 315 |
+
if debug:
|
| 316 |
+
print(f"aligned offset={offset}, avail_numel={avail_numel}")
|
| 317 |
+
|
| 318 |
+
# Sanity check
|
| 319 |
+
if offset != avail_numel:
|
| 320 |
+
raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
| 321 |
+
|
| 322 |
+
print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 326 |
+
exclude_frozen_parameters):
|
| 327 |
+
state_dict = OrderedDict()
|
| 328 |
+
|
| 329 |
+
# buffers
|
| 330 |
+
buffers = zero_model_states[0].buffers
|
| 331 |
+
state_dict.update(buffers)
|
| 332 |
+
if debug:
|
| 333 |
+
print(f"added {len(buffers)} buffers")
|
| 334 |
+
|
| 335 |
+
if not exclude_frozen_parameters:
|
| 336 |
+
_zero2_merge_frozen_params(state_dict, zero_model_states)
|
| 337 |
+
|
| 338 |
+
_zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
|
| 339 |
+
|
| 340 |
+
# recover shared parameters
|
| 341 |
+
for pair in zero_model_states[0].shared_params:
|
| 342 |
+
if pair[1] in state_dict:
|
| 343 |
+
state_dict[pair[0]] = state_dict[pair[1]]
|
| 344 |
+
|
| 345 |
+
return state_dict
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def zero3_partitioned_param_info(unpartitioned_numel, world_size):
|
| 349 |
+
remainder = unpartitioned_numel % world_size
|
| 350 |
+
padding_numel = (world_size - remainder) if remainder else 0
|
| 351 |
+
partitioned_numel = math.ceil(unpartitioned_numel / world_size)
|
| 352 |
+
return partitioned_numel, padding_numel
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
|
| 356 |
+
if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
|
| 357 |
+
return
|
| 358 |
+
|
| 359 |
+
if debug:
|
| 360 |
+
for i in range(world_size):
|
| 361 |
+
num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
|
| 362 |
+
print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
|
| 363 |
+
|
| 364 |
+
frozen_param_shapes = zero_model_states[0].frozen_param_shapes
|
| 365 |
+
wanted_params = len(frozen_param_shapes)
|
| 366 |
+
wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
|
| 367 |
+
avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
|
| 368 |
+
print(f'Frozen params: Have {avail_numel} numels to process.')
|
| 369 |
+
print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
|
| 370 |
+
|
| 371 |
+
total_params = 0
|
| 372 |
+
total_numel = 0
|
| 373 |
+
for name, shape in zero_model_states[0].frozen_param_shapes.items():
|
| 374 |
+
total_params += 1
|
| 375 |
+
unpartitioned_numel = shape.numel()
|
| 376 |
+
total_numel += unpartitioned_numel
|
| 377 |
+
|
| 378 |
+
param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
|
| 379 |
+
state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
|
| 380 |
+
|
| 381 |
+
partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
|
| 382 |
+
|
| 383 |
+
if debug:
|
| 384 |
+
print(
|
| 385 |
+
f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
|
| 386 |
+
)
|
| 387 |
+
|
| 388 |
+
print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
class GatheredTensor:
|
| 392 |
+
"""
|
| 393 |
+
A pseudo tensor that collects partitioned weights.
|
| 394 |
+
It is more memory efficient when there are multiple groups.
|
| 395 |
+
"""
|
| 396 |
+
|
| 397 |
+
def __init__(self, flat_groups, flat_groups_offset, offset, partitioned_numel, shape):
|
| 398 |
+
self.flat_groups = flat_groups
|
| 399 |
+
self.flat_groups_offset = flat_groups_offset
|
| 400 |
+
self.offset = offset
|
| 401 |
+
self.partitioned_numel = partitioned_numel
|
| 402 |
+
self.shape = shape
|
| 403 |
+
self.dtype = self.flat_groups[0][0].dtype
|
| 404 |
+
|
| 405 |
+
def contiguous(self):
|
| 406 |
+
"""
|
| 407 |
+
Merge partitioned weights from flat_groups into a single tensor.
|
| 408 |
+
"""
|
| 409 |
+
end_idx = self.offset + self.partitioned_numel
|
| 410 |
+
world_size = len(self.flat_groups)
|
| 411 |
+
pad_flat_param_chunks = []
|
| 412 |
+
|
| 413 |
+
for rank_i in range(world_size):
|
| 414 |
+
# for each rank, we need to collect weights from related group/groups
|
| 415 |
+
flat_groups_at_rank_i = self.flat_groups[rank_i]
|
| 416 |
+
start_group_id = None
|
| 417 |
+
end_group_id = None
|
| 418 |
+
for group_id in range(len(self.flat_groups_offset)):
|
| 419 |
+
if self.flat_groups_offset[group_id] <= self.offset < self.flat_groups_offset[group_id + 1]:
|
| 420 |
+
start_group_id = group_id
|
| 421 |
+
if self.flat_groups_offset[group_id] < end_idx <= self.flat_groups_offset[group_id + 1]:
|
| 422 |
+
end_group_id = group_id
|
| 423 |
+
break
|
| 424 |
+
# collect weights from related group/groups
|
| 425 |
+
for group_id in range(start_group_id, end_group_id + 1):
|
| 426 |
+
flat_tensor = flat_groups_at_rank_i[group_id]
|
| 427 |
+
start_offset = self.offset - self.flat_groups_offset[group_id]
|
| 428 |
+
end_offset = min(end_idx, self.flat_groups_offset[group_id + 1]) - self.flat_groups_offset[group_id]
|
| 429 |
+
pad_flat_param_chunks.append(flat_tensor[start_offset:end_offset])
|
| 430 |
+
|
| 431 |
+
# collect weights from all ranks
|
| 432 |
+
pad_flat_param = torch.cat(pad_flat_param_chunks, dim=0)
|
| 433 |
+
param = pad_flat_param[:self.shape.numel()].view(self.shape).contiguous()
|
| 434 |
+
return param
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
|
| 438 |
+
param_shapes = zero_model_states[0].param_shapes
|
| 439 |
+
avail_numel = sum([flat_group.numel() for flat_group in fp32_flat_groups[0]]) * world_size
|
| 440 |
+
|
| 441 |
+
# Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
|
| 442 |
+
# param, re-consolidating each param, while dealing with padding if any
|
| 443 |
+
|
| 444 |
+
# merge list of dicts, preserving order
|
| 445 |
+
param_shapes = {k: v for d in param_shapes for k, v in d.items()}
|
| 446 |
+
|
| 447 |
+
if debug:
|
| 448 |
+
for i in range(world_size):
|
| 449 |
+
print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
|
| 450 |
+
|
| 451 |
+
wanted_params = len(param_shapes)
|
| 452 |
+
wanted_numel = sum(shape.numel() for shape in param_shapes.values())
|
| 453 |
+
# not asserting if there is a mismatch due to possible padding
|
| 454 |
+
avail_numel = fp32_flat_groups[0].numel() * world_size
|
| 455 |
+
print(f"Trainable params: Have {avail_numel} numels to process.")
|
| 456 |
+
print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
|
| 457 |
+
|
| 458 |
+
# params
|
| 459 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
| 460 |
+
# out-of-core computing solution
|
| 461 |
+
offset = 0
|
| 462 |
+
total_numel = 0
|
| 463 |
+
total_params = 0
|
| 464 |
+
flat_groups_offset = [0] + list(np.cumsum([flat_tensor.numel() for flat_tensor in fp32_flat_groups[0]]))
|
| 465 |
+
for name, shape in tqdm(param_shapes.items(), desc='Gathering sharded weights'):
|
| 466 |
+
unpartitioned_numel = shape.numel()
|
| 467 |
+
total_numel += unpartitioned_numel
|
| 468 |
+
total_params += 1
|
| 469 |
+
partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
|
| 470 |
+
|
| 471 |
+
if debug:
|
| 472 |
+
print(
|
| 473 |
+
f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
# memory efficient tensor
|
| 477 |
+
tensor = GatheredTensor(fp32_flat_groups, flat_groups_offset, offset, partitioned_numel, shape)
|
| 478 |
+
state_dict[name] = tensor
|
| 479 |
+
offset += partitioned_numel
|
| 480 |
+
|
| 481 |
+
offset *= world_size
|
| 482 |
+
|
| 483 |
+
# Sanity check
|
| 484 |
+
if offset != avail_numel:
|
| 485 |
+
raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
| 486 |
+
|
| 487 |
+
print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
|
| 491 |
+
exclude_frozen_parameters):
|
| 492 |
+
state_dict = OrderedDict()
|
| 493 |
+
|
| 494 |
+
# buffers
|
| 495 |
+
buffers = zero_model_states[0].buffers
|
| 496 |
+
state_dict.update(buffers)
|
| 497 |
+
if debug:
|
| 498 |
+
print(f"added {len(buffers)} buffers")
|
| 499 |
+
|
| 500 |
+
if not exclude_frozen_parameters:
|
| 501 |
+
_zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
|
| 502 |
+
|
| 503 |
+
_zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
|
| 504 |
+
|
| 505 |
+
# recover shared parameters
|
| 506 |
+
for pair in zero_model_states[0].shared_params:
|
| 507 |
+
if pair[1] in state_dict:
|
| 508 |
+
state_dict[pair[0]] = state_dict[pair[1]]
|
| 509 |
+
|
| 510 |
+
return state_dict
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def to_torch_tensor(state_dict, return_empty_tensor=False):
|
| 514 |
+
"""
|
| 515 |
+
Convert state_dict of GatheredTensor to torch tensor
|
| 516 |
+
"""
|
| 517 |
+
torch_state_dict = {}
|
| 518 |
+
converted_tensors = {}
|
| 519 |
+
for name, tensor in state_dict.items():
|
| 520 |
+
tensor_id = id(tensor)
|
| 521 |
+
if tensor_id in converted_tensors: # shared tensors
|
| 522 |
+
shared_tensor = torch_state_dict[converted_tensors[tensor_id]]
|
| 523 |
+
torch_state_dict[name] = shared_tensor
|
| 524 |
+
else:
|
| 525 |
+
converted_tensors[tensor_id] = name
|
| 526 |
+
if return_empty_tensor:
|
| 527 |
+
torch_state_dict[name] = torch.empty(tensor.shape, dtype=tensor.dtype)
|
| 528 |
+
else:
|
| 529 |
+
torch_state_dict[name] = tensor.contiguous()
|
| 530 |
+
return torch_state_dict
|
| 531 |
+
|
| 532 |
+
|
| 533 |
+
def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
|
| 534 |
+
tag=None,
|
| 535 |
+
exclude_frozen_parameters=False,
|
| 536 |
+
lazy_mode=False):
|
| 537 |
+
"""
|
| 538 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
|
| 539 |
+
``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
|
| 540 |
+
via a model hub.
|
| 541 |
+
|
| 542 |
+
Args:
|
| 543 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder
|
| 544 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
|
| 545 |
+
- ``exclude_frozen_parameters``: exclude frozen parameters
|
| 546 |
+
- ``lazy_mode``: get state_dict in lazy mode. It returns a dict of pesduo tensor instead of torch tensor, which is more memory efficient.
|
| 547 |
+
Convert the pesduo tensor to torch tensor by ``.contiguous()``
|
| 548 |
+
|
| 549 |
+
Returns:
|
| 550 |
+
- pytorch ``state_dict``
|
| 551 |
+
|
| 552 |
+
A typical usage might be ::
|
| 553 |
+
|
| 554 |
+
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
|
| 555 |
+
# do the training and checkpoint saving
|
| 556 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
|
| 557 |
+
model = model.cpu() # move to cpu
|
| 558 |
+
model.load_state_dict(state_dict)
|
| 559 |
+
# submit to model hub or save the model to share with others
|
| 560 |
+
|
| 561 |
+
In this example the ``model`` will no longer be usable in the deepspeed context of the same
|
| 562 |
+
application. i.e. you will need to re-initialize the deepspeed engine, since
|
| 563 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
| 564 |
+
|
| 565 |
+
If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
|
| 566 |
+
|
| 567 |
+
Note: the above usage may not work if your application doesn't have sufficient free CPU memory.
|
| 568 |
+
You may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
|
| 569 |
+
the checkpoint. Or you can load state_dict in lazy mode ::
|
| 570 |
+
|
| 571 |
+
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
|
| 572 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, lazy_mode=True) # not on cpu
|
| 573 |
+
for name, lazy_tensor in state_dict.item():
|
| 574 |
+
tensor = lazy_tensor.contiguous() # to cpu
|
| 575 |
+
print(name, tensor)
|
| 576 |
+
# del tensor to release memory if it no longer in use
|
| 577 |
+
"""
|
| 578 |
+
if tag is None:
|
| 579 |
+
latest_path = os.path.join(checkpoint_dir, 'latest')
|
| 580 |
+
if os.path.isfile(latest_path):
|
| 581 |
+
with open(latest_path, 'r') as fd:
|
| 582 |
+
tag = fd.read().strip()
|
| 583 |
+
else:
|
| 584 |
+
raise ValueError(f"Unable to find 'latest' file at {latest_path}")
|
| 585 |
+
|
| 586 |
+
ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
|
| 587 |
+
|
| 588 |
+
if not os.path.isdir(ds_checkpoint_dir):
|
| 589 |
+
raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
|
| 590 |
+
|
| 591 |
+
state_dict = _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
|
| 592 |
+
if lazy_mode:
|
| 593 |
+
return state_dict
|
| 594 |
+
else:
|
| 595 |
+
return to_torch_tensor(state_dict)
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
|
| 599 |
+
output_dir,
|
| 600 |
+
max_shard_size="5GB",
|
| 601 |
+
safe_serialization=False,
|
| 602 |
+
tag=None,
|
| 603 |
+
exclude_frozen_parameters=False):
|
| 604 |
+
"""
|
| 605 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
|
| 606 |
+
loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
|
| 607 |
+
|
| 608 |
+
Args:
|
| 609 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
| 610 |
+
- ``output_dir``: directory to the pytorch fp32 state_dict output files
|
| 611 |
+
- ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
|
| 612 |
+
- ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
|
| 613 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
|
| 614 |
+
- ``exclude_frozen_parameters``: exclude frozen parameters
|
| 615 |
+
"""
|
| 616 |
+
|
| 617 |
+
# Dependency pre-check
|
| 618 |
+
if safe_serialization:
|
| 619 |
+
try:
|
| 620 |
+
from safetensors.torch import save_file
|
| 621 |
+
except ImportError:
|
| 622 |
+
print('If you want to use `safe_serialization`, please `pip install safetensors`')
|
| 623 |
+
raise
|
| 624 |
+
if max_shard_size is not None:
|
| 625 |
+
try:
|
| 626 |
+
from huggingface_hub import split_torch_state_dict_into_shards
|
| 627 |
+
except ImportError:
|
| 628 |
+
print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
|
| 629 |
+
raise
|
| 630 |
+
|
| 631 |
+
# Convert zero checkpoint to state_dict
|
| 632 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
|
| 633 |
+
tag,
|
| 634 |
+
exclude_frozen_parameters,
|
| 635 |
+
lazy_mode=True)
|
| 636 |
+
|
| 637 |
+
# Shard the model if it is too big.
|
| 638 |
+
weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
|
| 639 |
+
if max_shard_size is not None:
|
| 640 |
+
filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
|
| 641 |
+
# an memory-efficient approach for sharding
|
| 642 |
+
empty_state_dict = to_torch_tensor(state_dict, return_empty_tensor=True)
|
| 643 |
+
state_dict_split = split_torch_state_dict_into_shards(empty_state_dict,
|
| 644 |
+
filename_pattern=filename_pattern,
|
| 645 |
+
max_shard_size=max_shard_size)
|
| 646 |
+
else:
|
| 647 |
+
from collections import namedtuple
|
| 648 |
+
StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
|
| 649 |
+
state_dict_split = StateDictSplit(is_sharded=False,
|
| 650 |
+
filename_to_tensors={weights_name: list(state_dict.keys())})
|
| 651 |
+
|
| 652 |
+
# Save the model by shard
|
| 653 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 654 |
+
filename_to_tensors = state_dict_split.filename_to_tensors.items()
|
| 655 |
+
for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
|
| 656 |
+
shard_state_dict = {tensor_name: state_dict[tensor_name] for tensor_name in tensors}
|
| 657 |
+
shard_state_dict = to_torch_tensor(shard_state_dict)
|
| 658 |
+
output_path = os.path.join(output_dir, shard_file)
|
| 659 |
+
if safe_serialization:
|
| 660 |
+
save_file(shard_state_dict, output_path, metadata={"format": "pt"})
|
| 661 |
+
else:
|
| 662 |
+
torch.save(shard_state_dict, output_path)
|
| 663 |
+
# release the memory of current shard
|
| 664 |
+
for tensor_name in list(shard_state_dict.keys()):
|
| 665 |
+
del state_dict[tensor_name]
|
| 666 |
+
del shard_state_dict[tensor_name]
|
| 667 |
+
del shard_state_dict
|
| 668 |
+
gc.collect()
|
| 669 |
+
|
| 670 |
+
# Save index if sharded
|
| 671 |
+
if state_dict_split.is_sharded:
|
| 672 |
+
index = {
|
| 673 |
+
"metadata": state_dict_split.metadata,
|
| 674 |
+
"weight_map": state_dict_split.tensor_to_filename,
|
| 675 |
+
}
|
| 676 |
+
save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
|
| 677 |
+
save_index_file = os.path.join(output_dir, save_index_file)
|
| 678 |
+
with open(save_index_file, "w", encoding="utf-8") as f:
|
| 679 |
+
content = json.dumps(index, indent=2, sort_keys=True) + "\n"
|
| 680 |
+
f.write(content)
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
|
| 684 |
+
"""
|
| 685 |
+
1. Put the provided model to cpu
|
| 686 |
+
2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
|
| 687 |
+
3. Load it into the provided model
|
| 688 |
+
|
| 689 |
+
Args:
|
| 690 |
+
- ``model``: the model object to update
|
| 691 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
| 692 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
|
| 693 |
+
|
| 694 |
+
Returns:
|
| 695 |
+
- ``model`: modified model
|
| 696 |
+
|
| 697 |
+
Make sure you have plenty of CPU memory available before you call this function. If you don't
|
| 698 |
+
have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
|
| 699 |
+
conveniently placed for you in the checkpoint folder.
|
| 700 |
+
|
| 701 |
+
A typical usage might be ::
|
| 702 |
+
|
| 703 |
+
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
|
| 704 |
+
model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
|
| 705 |
+
# submit to model hub or save the model to share with others
|
| 706 |
+
|
| 707 |
+
Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
|
| 708 |
+
of the same application. i.e. you will need to re-initialize the deepspeed engine, since
|
| 709 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
| 710 |
+
|
| 711 |
+
"""
|
| 712 |
+
logger.info(f"Extracting fp32 weights")
|
| 713 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
|
| 714 |
+
|
| 715 |
+
logger.info(f"Overwriting model with fp32 weights")
|
| 716 |
+
model = model.cpu()
|
| 717 |
+
model.load_state_dict(state_dict, strict=False)
|
| 718 |
+
|
| 719 |
+
return model
|
| 720 |
+
|
| 721 |
+
|
| 722 |
+
if __name__ == "__main__":
|
| 723 |
+
parser = argparse.ArgumentParser()
|
| 724 |
+
parser.add_argument("checkpoint_dir",
|
| 725 |
+
type=str,
|
| 726 |
+
help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
|
| 727 |
+
parser.add_argument("output_dir",
|
| 728 |
+
type=str,
|
| 729 |
+
help="directory to the pytorch fp32 state_dict output files"
|
| 730 |
+
"(e.g. path/checkpoint-12-output/)")
|
| 731 |
+
parser.add_argument(
|
| 732 |
+
"--max_shard_size",
|
| 733 |
+
type=str,
|
| 734 |
+
default="5GB",
|
| 735 |
+
help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
|
| 736 |
+
"lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
|
| 737 |
+
"We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
|
| 738 |
+
"without CPU OOM issues.")
|
| 739 |
+
parser.add_argument(
|
| 740 |
+
"--safe_serialization",
|
| 741 |
+
default=False,
|
| 742 |
+
action='store_true',
|
| 743 |
+
help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
|
| 744 |
+
parser.add_argument("-t",
|
| 745 |
+
"--tag",
|
| 746 |
+
type=str,
|
| 747 |
+
default=None,
|
| 748 |
+
help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
|
| 749 |
+
parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
|
| 750 |
+
parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
|
| 751 |
+
args = parser.parse_args()
|
| 752 |
+
|
| 753 |
+
debug = args.debug
|
| 754 |
+
|
| 755 |
+
convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
|
| 756 |
+
args.output_dir,
|
| 757 |
+
max_shard_size=args.max_shard_size,
|
| 758 |
+
safe_serialization=args.safe_serialization,
|
| 759 |
+
tag=args.tag,
|
| 760 |
+
exclude_frozen_parameters=args.exclude_frozen_parameters)
|