Feature Extraction
Transformers
Safetensors
llama_bidirec
mergekit
Merge
custom_code
text-embeddings-inference
8-bit precision
quanto
Instructions to use KwangHwi/quantization_v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use KwangHwi/quantization_v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="KwangHwi/quantization_v2", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("KwangHwi/quantization_v2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add files using upload-large-folder tool
Browse files- .gitattributes +1 -0
- .ipynb_checkpoints/README-checkpoint.md +77 -0
- .ipynb_checkpoints/config-checkpoint.json +43 -0
- .ipynb_checkpoints/llama_bidirectional_model-checkpoint.py +226 -0
- .ipynb_checkpoints/mergekit_config-checkpoint.yml +48 -0
- 1_Pooling/.ipynb_checkpoints/config-checkpoint.json +10 -0
- 1_Pooling/config.json +10 -0
- README.md +77 -0
- __pycache__/llama_bidirectional_model.cpython-312.pyc +0 -0
- config.json +47 -0
- config_1.json +40 -0
- config_sentence_transformers.json +14 -0
- llama_bidirectional_model.py +226 -0
- mergekit_config.yml +48 -0
- model.safetensors +3 -0
- modules.json +20 -0
- pooling.py +29 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +23 -0
- tokenizer.json +3 -0
- tokenizer_config.json +19 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
.ipynb_checkpoints/README-checkpoint.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: []
|
| 3 |
+
library_name: transformers
|
| 4 |
+
tags:
|
| 5 |
+
- mergekit
|
| 6 |
+
- merge
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
# output_merge_multiSFT_v6_1
|
| 10 |
+
|
| 11 |
+
This is a merge of pre-trained language models created using [mergekit](https://github.com/cg123/mergekit).
|
| 12 |
+
|
| 13 |
+
## Merge Details
|
| 14 |
+
### Merge Method
|
| 15 |
+
|
| 16 |
+
This model was merged using the [SLERP](https://en.wikipedia.org/wiki/Slerp) merge method.
|
| 17 |
+
|
| 18 |
+
### Models Merged
|
| 19 |
+
|
| 20 |
+
The following models were included in the merge:
|
| 21 |
+
* /workspace/storage-shared/cnm/embedding/code/llama_1B_legal_retrieval_v2_2.3M_clean_150726_finetune2_07150726/checkpoint-8000
|
| 22 |
+
* /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6
|
| 23 |
+
|
| 24 |
+
### Configuration
|
| 25 |
+
|
| 26 |
+
The following YAML configuration was used to produce this model:
|
| 27 |
+
|
| 28 |
+
```yaml
|
| 29 |
+
# slices:
|
| 30 |
+
# - sources:
|
| 31 |
+
# - model: psmathur/orca_mini_v3_13b
|
| 32 |
+
# layer_range: [0, 40]
|
| 33 |
+
# - model: garage-bAInd/Platypus2-13B
|
| 34 |
+
# layer_range: [0, 40]
|
| 35 |
+
# # or, the equivalent models: syntax:
|
| 36 |
+
# # models:
|
| 37 |
+
# # - model: psmathur/orca_mini_v3_13b
|
| 38 |
+
# # - model: garage-bAInd/Platypus2-13B
|
| 39 |
+
# merge_method: slerp
|
| 40 |
+
# base_model: psmathur/orca_mini_v3_13b
|
| 41 |
+
# parameters:
|
| 42 |
+
# t:
|
| 43 |
+
# - filter: self_attn
|
| 44 |
+
# value: [0, 0.5, 0.3, 0.7, 1]
|
| 45 |
+
# - filter: mlp
|
| 46 |
+
# value: [1, 0.5, 0.7, 0.3, 0]
|
| 47 |
+
# - value: 0.5 # fallback for rest of tensors
|
| 48 |
+
# dtype: float16
|
| 49 |
+
# slices:
|
| 50 |
+
models:
|
| 51 |
+
- model: /workspace/storage-shared/cnm/embedding/code/llama_1B_legal_retrieval_v2_2.3M_clean_150726_finetune2_07150726/checkpoint-8000 # Mô hình A (Base gốc)
|
| 52 |
+
# layer_range: [0, 36]
|
| 53 |
+
- model: /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6 # Mô hình B (Đã Finetune)
|
| 54 |
+
# layer_range: [0, 36]
|
| 55 |
+
merge_method: slerp
|
| 56 |
+
base_model: /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6 # Mô hình B (Đã Finetune)
|
| 57 |
+
parameters:
|
| 58 |
+
t:
|
| 59 |
+
#- filter: self_attn
|
| 60 |
+
- filter: layers
|
| 61 |
+
value: [0.2, 0.3, 0.5, 0.6, 0.7, 0.8]
|
| 62 |
+
#- filter: mlp
|
| 63 |
+
# value: [0.2, 0.3, 0.5, 0.6, 0.7, 0.8]
|
| 64 |
+
- value: 0.5 # fallback cho layernorm
|
| 65 |
+
dtype: bfloat16
|
| 66 |
+
|
| 67 |
+
# models:
|
| 68 |
+
# - model: /workspace/storage-shared/cnm/cuongnq23/project_embeding/models/Qwen/Qwen3-Embedding-8B
|
| 69 |
+
# - model: /workspace/storage-shared/cnm/embedding/code/qwen8b_SFT_kalm_vnlaw_3M/checkpoint-20000
|
| 70 |
+
# merge_method: slerp
|
| 71 |
+
# base_model: /workspace/storage-shared/cnm/cuongnq23/project_embeding/models/Qwen/Qwen3-Embedding-8B
|
| 72 |
+
# parameters:
|
| 73 |
+
# t:
|
| 74 |
+
# # Trượt dốc từ 10% (đáy) lên 90% (đỉnh)
|
| 75 |
+
# - value: [0.1, 0.3, 0.5, 0.7, 0.9]
|
| 76 |
+
# dtype: bfloat16
|
| 77 |
+
```
|
.ipynb_checkpoints/config-checkpoint.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "nvidia/llama-3.2-nv-embedqa-1b-v2",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"LlamaBidirectionalModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_bias": false,
|
| 7 |
+
"attention_dropout": 0.0,
|
| 8 |
+
"auto_map": {
|
| 9 |
+
"AutoConfig": "llama_bidirectional_model.LlamaBidirectionalConfig",
|
| 10 |
+
"AutoModel": "llama_bidirectional_model.LlamaBidirectionalModel"
|
| 11 |
+
},
|
| 12 |
+
"bos_token_id": 128000,
|
| 13 |
+
"eos_token_id": 128001,
|
| 14 |
+
"head_dim": 64,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"hidden_size": 2048,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 8192,
|
| 19 |
+
"max_position_embeddings": 131072,
|
| 20 |
+
"mlp_bias": false,
|
| 21 |
+
"model_type": "llama_bidirec",
|
| 22 |
+
"num_attention_heads": 32,
|
| 23 |
+
"num_hidden_layers": 16,
|
| 24 |
+
"num_key_value_heads": 8,
|
| 25 |
+
"pooling": "avg",
|
| 26 |
+
"pretraining_tp": 1,
|
| 27 |
+
"rms_norm_eps": 1e-05,
|
| 28 |
+
"rope_scaling": {
|
| 29 |
+
"factor": 32.0,
|
| 30 |
+
"high_freq_factor": 4.0,
|
| 31 |
+
"low_freq_factor": 1.0,
|
| 32 |
+
"original_max_position_embeddings": 8192,
|
| 33 |
+
"rope_type": "llama3",
|
| 34 |
+
"rope_theta": 500000.0
|
| 35 |
+
},
|
| 36 |
+
"rope_theta": 500000.0,
|
| 37 |
+
"tie_word_embeddings": true,
|
| 38 |
+
"torch_dtype": "bfloat16",
|
| 39 |
+
"transformers_version": "4.44.2",
|
| 40 |
+
"use_cache": true,
|
| 41 |
+
"vocab_size": 128256,
|
| 42 |
+
"use_bidirectional_attention": true
|
| 43 |
+
}
|
.ipynb_checkpoints/llama_bidirectional_model-checkpoint.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0.
|
| 3 |
+
"""
|
| 4 |
+
Bidirectional Llama model for embedding tasks.
|
| 5 |
+
|
| 6 |
+
This module provides a modified LlamaModel that uses bidirectional (non-causal)
|
| 7 |
+
attention, suitable for generating embeddings where each token should attend
|
| 8 |
+
to all other tokens in the sequence.
|
| 9 |
+
|
| 10 |
+
Supports transformers version 4.44 and above with a unified forward() implementation.
|
| 11 |
+
|
| 12 |
+
Version compatibility notes:
|
| 13 |
+
- transformers 4.47: Setting _attn_implementation in __init__ had no effect due to
|
| 14 |
+
attention initialization order
|
| 15 |
+
- transformers 4.48+: Attention refactor (transformers#35235) activated the
|
| 16 |
+
_attn_implementation setting, which defaulted to "eager" instead of "sdpa"
|
| 17 |
+
- transformers < 4.53: LlamaModel has _update_causal_mask method that can be overridden
|
| 18 |
+
- transformers 4.53+: _update_causal_mask removed; masking moved to masking_utils module,
|
| 19 |
+
necessitating a full forward() override for custom attention masks
|
| 20 |
+
- transformers < 4.54: Decoder layer returns tuple, uses past_key_value (singular)
|
| 21 |
+
- transformers 4.54-4.55: Decoder layer returns tensor, uses past_key_value (singular)
|
| 22 |
+
- transformers 4.56+: Decoder layer returns tensor, uses past_key_values (plural),
|
| 23 |
+
DynamicCache accepts config parameter
|
| 24 |
+
- transformers 5.0+: Has native create_bidirectional_mask in masking_utils
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
import inspect
|
| 28 |
+
|
| 29 |
+
import torch
|
| 30 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 31 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast
|
| 32 |
+
from transformers.models.llama.configuration_llama import LlamaConfig
|
| 33 |
+
from transformers.models.llama.modeling_llama import LlamaDecoderLayer, LlamaModel
|
| 34 |
+
from transformers.utils import logging
|
| 35 |
+
|
| 36 |
+
logger = logging.get_logger(__name__)
|
| 37 |
+
|
| 38 |
+
# Check if native create_bidirectional_mask exists (transformers >= 5.0)
|
| 39 |
+
try:
|
| 40 |
+
from transformers.masking_utils import create_bidirectional_mask
|
| 41 |
+
|
| 42 |
+
_HAS_NATIVE_BIDIRECTIONAL_MASK = True
|
| 43 |
+
except ImportError:
|
| 44 |
+
from transformers.modeling_attn_mask_utils import _prepare_4d_attention_mask
|
| 45 |
+
|
| 46 |
+
_HAS_NATIVE_BIDIRECTIONAL_MASK = False
|
| 47 |
+
|
| 48 |
+
# Detect API differences via introspection
|
| 49 |
+
_decoder_forward_params = inspect.signature(LlamaDecoderLayer.forward).parameters
|
| 50 |
+
_dynamic_cache_init_params = inspect.signature(DynamicCache.__init__).parameters
|
| 51 |
+
|
| 52 |
+
# past_key_value (singular) in < 4.56, past_key_values (plural) in >= 4.56
|
| 53 |
+
_USE_PLURAL_CACHE_PARAM = "past_key_values" in _decoder_forward_params
|
| 54 |
+
# DynamicCache accepts config parameter in >= 4.56
|
| 55 |
+
_DYNAMIC_CACHE_ACCEPTS_CONFIG = "config" in _dynamic_cache_init_params
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class LlamaBidirectionalConfig(LlamaConfig):
|
| 59 |
+
"""Configuration for LlamaBidirectionalModel with pooling and temperature settings."""
|
| 60 |
+
|
| 61 |
+
model_type = "llama_bidirec"
|
| 62 |
+
|
| 63 |
+
def __init__(
|
| 64 |
+
self, pooling: str = "avg", temperature: float = 1.0, **kwargs
|
| 65 |
+
) -> None:
|
| 66 |
+
"""
|
| 67 |
+
Initialize bidirectional Llama configuration.
|
| 68 |
+
|
| 69 |
+
Args:
|
| 70 |
+
pooling: Pooling strategy for embeddings ("avg", "cls", "last", etc.)
|
| 71 |
+
temperature: Temperature scaling for embeddings
|
| 72 |
+
**kwargs: Additional arguments passed to LlamaConfig
|
| 73 |
+
"""
|
| 74 |
+
self.pooling = pooling
|
| 75 |
+
self.temperature = temperature
|
| 76 |
+
super().__init__(**kwargs)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class LlamaBidirectionalModel(LlamaModel):
|
| 80 |
+
"""
|
| 81 |
+
LlamaModel modified to use bidirectional (non-causal) attention.
|
| 82 |
+
|
| 83 |
+
In standard Llama, each token can only attend to previous tokens (causal attention).
|
| 84 |
+
This model removes that restriction, allowing each token to attend to all tokens
|
| 85 |
+
in the sequence, which is useful for embedding tasks.
|
| 86 |
+
|
| 87 |
+
The key modifications are:
|
| 88 |
+
1. Setting is_causal=False on all attention layers
|
| 89 |
+
2. Using a bidirectional attention mask instead of causal mask
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
config_class = LlamaBidirectionalConfig
|
| 93 |
+
|
| 94 |
+
def __init__(self, config: LlamaConfig) -> None:
|
| 95 |
+
super().__init__(config)
|
| 96 |
+
for layer in self.layers:
|
| 97 |
+
layer.self_attn.is_causal = False
|
| 98 |
+
|
| 99 |
+
def _create_bidirectional_mask(
|
| 100 |
+
self,
|
| 101 |
+
input_embeds: torch.Tensor,
|
| 102 |
+
attention_mask: torch.Tensor | None,
|
| 103 |
+
) -> torch.Tensor | None:
|
| 104 |
+
"""
|
| 105 |
+
Create bidirectional attention mask.
|
| 106 |
+
|
| 107 |
+
Args:
|
| 108 |
+
input_embeds: Input embeddings tensor of shape (batch_size, seq_len, hidden_size)
|
| 109 |
+
attention_mask: Optional 2D attention mask of shape (batch_size, seq_len)
|
| 110 |
+
where 1 indicates tokens to attend to and 0 indicates masked tokens
|
| 111 |
+
|
| 112 |
+
Returns:
|
| 113 |
+
4D attention mask suitable for the attention implementation, or None
|
| 114 |
+
if no masking is needed
|
| 115 |
+
"""
|
| 116 |
+
if attention_mask is None:
|
| 117 |
+
return None
|
| 118 |
+
|
| 119 |
+
if _HAS_NATIVE_BIDIRECTIONAL_MASK:
|
| 120 |
+
return create_bidirectional_mask(
|
| 121 |
+
config=self.config,
|
| 122 |
+
input_embeds=input_embeds,
|
| 123 |
+
attention_mask=attention_mask,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
# Fallback for transformers < 5.0 without create_bidirectional_mask
|
| 127 |
+
|
| 128 |
+
# Flash attention handles 2D masks internally; only pass mask if there
|
| 129 |
+
# are actually masked tokens (zeros), otherwise return None for efficiency
|
| 130 |
+
if getattr(self.config, "_attn_implementation", None) == "flash_attention_2":
|
| 131 |
+
has_masked_tokens = (attention_mask == 0).any()
|
| 132 |
+
return attention_mask if has_masked_tokens else None
|
| 133 |
+
|
| 134 |
+
return _prepare_4d_attention_mask(attention_mask, input_embeds.dtype)
|
| 135 |
+
|
| 136 |
+
def forward(
|
| 137 |
+
self,
|
| 138 |
+
input_ids: torch.LongTensor | None = None,
|
| 139 |
+
attention_mask: torch.Tensor | None = None,
|
| 140 |
+
position_ids: torch.LongTensor | None = None,
|
| 141 |
+
past_key_values: Cache | None = None,
|
| 142 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 143 |
+
cache_position: torch.LongTensor | None = None,
|
| 144 |
+
use_cache: bool | None = None,
|
| 145 |
+
**kwargs,
|
| 146 |
+
) -> BaseModelOutputWithPast:
|
| 147 |
+
"""
|
| 148 |
+
Forward pass with bidirectional attention.
|
| 149 |
+
|
| 150 |
+
Args:
|
| 151 |
+
input_ids: Input token IDs of shape (batch_size, seq_len)
|
| 152 |
+
attention_mask: Attention mask of shape (batch_size, seq_len)
|
| 153 |
+
position_ids: Position IDs for rotary embeddings
|
| 154 |
+
past_key_values: Cached key/value states for incremental decoding
|
| 155 |
+
inputs_embeds: Pre-computed input embeddings (alternative to input_ids)
|
| 156 |
+
cache_position: Position indices for cache updates
|
| 157 |
+
use_cache: Whether to return cached key/value states
|
| 158 |
+
**kwargs: Additional arguments passed to decoder layers
|
| 159 |
+
|
| 160 |
+
Returns:
|
| 161 |
+
BaseModelOutputWithPast containing last_hidden_state and past_key_values
|
| 162 |
+
"""
|
| 163 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 164 |
+
raise ValueError(
|
| 165 |
+
"You must specify exactly one of input_ids or inputs_embeds"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
if inputs_embeds is None:
|
| 169 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 170 |
+
|
| 171 |
+
# Initialize cache if needed
|
| 172 |
+
if use_cache and past_key_values is None:
|
| 173 |
+
if _DYNAMIC_CACHE_ACCEPTS_CONFIG:
|
| 174 |
+
past_key_values = DynamicCache(config=self.config)
|
| 175 |
+
else:
|
| 176 |
+
past_key_values = DynamicCache()
|
| 177 |
+
|
| 178 |
+
if cache_position is None:
|
| 179 |
+
past_seen_tokens = (
|
| 180 |
+
past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 181 |
+
)
|
| 182 |
+
cache_position = torch.arange(
|
| 183 |
+
past_seen_tokens,
|
| 184 |
+
past_seen_tokens + inputs_embeds.shape[1],
|
| 185 |
+
device=inputs_embeds.device,
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
if position_ids is None:
|
| 189 |
+
position_ids = cache_position.unsqueeze(0)
|
| 190 |
+
|
| 191 |
+
bidirectional_mask = self._create_bidirectional_mask(
|
| 192 |
+
inputs_embeds, attention_mask
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
hidden_states = inputs_embeds
|
| 196 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 197 |
+
|
| 198 |
+
# Build decoder layer kwargs with correct cache parameter name
|
| 199 |
+
# (past_key_value in < 4.56, past_key_values in >= 4.56)
|
| 200 |
+
layer_kwargs = {
|
| 201 |
+
"attention_mask": bidirectional_mask,
|
| 202 |
+
"position_ids": position_ids,
|
| 203 |
+
"use_cache": use_cache,
|
| 204 |
+
"cache_position": cache_position,
|
| 205 |
+
"position_embeddings": position_embeddings,
|
| 206 |
+
}
|
| 207 |
+
if _USE_PLURAL_CACHE_PARAM:
|
| 208 |
+
layer_kwargs["past_key_values"] = past_key_values
|
| 209 |
+
else:
|
| 210 |
+
layer_kwargs["past_key_value"] = past_key_values
|
| 211 |
+
|
| 212 |
+
for decoder_layer in self.layers[: self.config.num_hidden_layers]:
|
| 213 |
+
layer_outputs = decoder_layer(hidden_states, **layer_kwargs)
|
| 214 |
+
|
| 215 |
+
# Decoder returns tuple in < 4.54, tensor in >= 4.54
|
| 216 |
+
if isinstance(layer_outputs, tuple):
|
| 217 |
+
hidden_states = layer_outputs[0]
|
| 218 |
+
else:
|
| 219 |
+
hidden_states = layer_outputs
|
| 220 |
+
|
| 221 |
+
hidden_states = self.norm(hidden_states)
|
| 222 |
+
|
| 223 |
+
return BaseModelOutputWithPast(
|
| 224 |
+
last_hidden_state=hidden_states,
|
| 225 |
+
past_key_values=past_key_values,
|
| 226 |
+
)
|
.ipynb_checkpoints/mergekit_config-checkpoint.yml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# slices:
|
| 2 |
+
# - sources:
|
| 3 |
+
# - model: psmathur/orca_mini_v3_13b
|
| 4 |
+
# layer_range: [0, 40]
|
| 5 |
+
# - model: garage-bAInd/Platypus2-13B
|
| 6 |
+
# layer_range: [0, 40]
|
| 7 |
+
# # or, the equivalent models: syntax:
|
| 8 |
+
# # models:
|
| 9 |
+
# # - model: psmathur/orca_mini_v3_13b
|
| 10 |
+
# # - model: garage-bAInd/Platypus2-13B
|
| 11 |
+
# merge_method: slerp
|
| 12 |
+
# base_model: psmathur/orca_mini_v3_13b
|
| 13 |
+
# parameters:
|
| 14 |
+
# t:
|
| 15 |
+
# - filter: self_attn
|
| 16 |
+
# value: [0, 0.5, 0.3, 0.7, 1]
|
| 17 |
+
# - filter: mlp
|
| 18 |
+
# value: [1, 0.5, 0.7, 0.3, 0]
|
| 19 |
+
# - value: 0.5 # fallback for rest of tensors
|
| 20 |
+
# dtype: float16
|
| 21 |
+
# slices:
|
| 22 |
+
models:
|
| 23 |
+
- model: /workspace/storage-shared/cnm/embedding/code/llama_1B_legal_retrieval_v2_2.3M_clean_150726_finetune2_07150726/checkpoint-8000 # Mô hình A (Base gốc)
|
| 24 |
+
# layer_range: [0, 36]
|
| 25 |
+
- model: /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6 # Mô hình B (Đã Finetune)
|
| 26 |
+
# layer_range: [0, 36]
|
| 27 |
+
merge_method: slerp
|
| 28 |
+
base_model: /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6 # Mô hình B (Đã Finetune)
|
| 29 |
+
parameters:
|
| 30 |
+
t:
|
| 31 |
+
#- filter: self_attn
|
| 32 |
+
- filter: layers
|
| 33 |
+
value: [0.2, 0.3, 0.5, 0.6, 0.7, 0.8]
|
| 34 |
+
#- filter: mlp
|
| 35 |
+
# value: [0.2, 0.3, 0.5, 0.6, 0.7, 0.8]
|
| 36 |
+
- value: 0.5 # fallback cho layernorm
|
| 37 |
+
dtype: bfloat16
|
| 38 |
+
|
| 39 |
+
# models:
|
| 40 |
+
# - model: /workspace/storage-shared/cnm/cuongnq23/project_embeding/models/Qwen/Qwen3-Embedding-8B
|
| 41 |
+
# - model: /workspace/storage-shared/cnm/embedding/code/qwen8b_SFT_kalm_vnlaw_3M/checkpoint-20000
|
| 42 |
+
# merge_method: slerp
|
| 43 |
+
# base_model: /workspace/storage-shared/cnm/cuongnq23/project_embeding/models/Qwen/Qwen3-Embedding-8B
|
| 44 |
+
# parameters:
|
| 45 |
+
# t:
|
| 46 |
+
# # Trượt dốc từ 10% (đáy) lên 90% (đỉnh)
|
| 47 |
+
# - value: [0.1, 0.3, 0.5, 0.7, 0.9]
|
| 48 |
+
# dtype: bfloat16
|
1_Pooling/.ipynb_checkpoints/config-checkpoint.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"word_embedding_dimension": 2048,
|
| 3 |
+
"pooling_mode_cls_token": false,
|
| 4 |
+
"pooling_mode_mean_tokens": true,
|
| 5 |
+
"pooling_mode_max_tokens": false,
|
| 6 |
+
"pooling_mode_mean_sqrt_len_tokens": false,
|
| 7 |
+
"pooling_mode_weightedmean_tokens": false,
|
| 8 |
+
"pooling_mode_lasttoken": false,
|
| 9 |
+
"include_prompt": true
|
| 10 |
+
}
|
1_Pooling/config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"word_embedding_dimension": 2048,
|
| 3 |
+
"pooling_mode_cls_token": false,
|
| 4 |
+
"pooling_mode_mean_tokens": true,
|
| 5 |
+
"pooling_mode_max_tokens": false,
|
| 6 |
+
"pooling_mode_mean_sqrt_len_tokens": false,
|
| 7 |
+
"pooling_mode_weightedmean_tokens": false,
|
| 8 |
+
"pooling_mode_lasttoken": false,
|
| 9 |
+
"include_prompt": true
|
| 10 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: []
|
| 3 |
+
library_name: transformers
|
| 4 |
+
tags:
|
| 5 |
+
- mergekit
|
| 6 |
+
- merge
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
# output_merge_multiSFT_v6_1
|
| 10 |
+
|
| 11 |
+
This is a merge of pre-trained language models created using [mergekit](https://github.com/cg123/mergekit).
|
| 12 |
+
|
| 13 |
+
## Merge Details
|
| 14 |
+
### Merge Method
|
| 15 |
+
|
| 16 |
+
This model was merged using the [SLERP](https://en.wikipedia.org/wiki/Slerp) merge method.
|
| 17 |
+
|
| 18 |
+
### Models Merged
|
| 19 |
+
|
| 20 |
+
The following models were included in the merge:
|
| 21 |
+
* /workspace/storage-shared/cnm/embedding/code/llama_1B_legal_retrieval_v2_2.3M_clean_150726_finetune2_07150726/checkpoint-8000
|
| 22 |
+
* /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6
|
| 23 |
+
|
| 24 |
+
### Configuration
|
| 25 |
+
|
| 26 |
+
The following YAML configuration was used to produce this model:
|
| 27 |
+
|
| 28 |
+
```yaml
|
| 29 |
+
# slices:
|
| 30 |
+
# - sources:
|
| 31 |
+
# - model: psmathur/orca_mini_v3_13b
|
| 32 |
+
# layer_range: [0, 40]
|
| 33 |
+
# - model: garage-bAInd/Platypus2-13B
|
| 34 |
+
# layer_range: [0, 40]
|
| 35 |
+
# # or, the equivalent models: syntax:
|
| 36 |
+
# # models:
|
| 37 |
+
# # - model: psmathur/orca_mini_v3_13b
|
| 38 |
+
# # - model: garage-bAInd/Platypus2-13B
|
| 39 |
+
# merge_method: slerp
|
| 40 |
+
# base_model: psmathur/orca_mini_v3_13b
|
| 41 |
+
# parameters:
|
| 42 |
+
# t:
|
| 43 |
+
# - filter: self_attn
|
| 44 |
+
# value: [0, 0.5, 0.3, 0.7, 1]
|
| 45 |
+
# - filter: mlp
|
| 46 |
+
# value: [1, 0.5, 0.7, 0.3, 0]
|
| 47 |
+
# - value: 0.5 # fallback for rest of tensors
|
| 48 |
+
# dtype: float16
|
| 49 |
+
# slices:
|
| 50 |
+
models:
|
| 51 |
+
- model: /workspace/storage-shared/cnm/embedding/code/llama_1B_legal_retrieval_v2_2.3M_clean_150726_finetune2_07150726/checkpoint-8000 # Mô hình A (Base gốc)
|
| 52 |
+
# layer_range: [0, 36]
|
| 53 |
+
- model: /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6 # Mô hình B (Đã Finetune)
|
| 54 |
+
# layer_range: [0, 36]
|
| 55 |
+
merge_method: slerp
|
| 56 |
+
base_model: /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6 # Mô hình B (Đã Finetune)
|
| 57 |
+
parameters:
|
| 58 |
+
t:
|
| 59 |
+
#- filter: self_attn
|
| 60 |
+
- filter: layers
|
| 61 |
+
value: [0.2, 0.3, 0.5, 0.6, 0.7, 0.8]
|
| 62 |
+
#- filter: mlp
|
| 63 |
+
# value: [0.2, 0.3, 0.5, 0.6, 0.7, 0.8]
|
| 64 |
+
- value: 0.5 # fallback cho layernorm
|
| 65 |
+
dtype: bfloat16
|
| 66 |
+
|
| 67 |
+
# models:
|
| 68 |
+
# - model: /workspace/storage-shared/cnm/cuongnq23/project_embeding/models/Qwen/Qwen3-Embedding-8B
|
| 69 |
+
# - model: /workspace/storage-shared/cnm/embedding/code/qwen8b_SFT_kalm_vnlaw_3M/checkpoint-20000
|
| 70 |
+
# merge_method: slerp
|
| 71 |
+
# base_model: /workspace/storage-shared/cnm/cuongnq23/project_embeding/models/Qwen/Qwen3-Embedding-8B
|
| 72 |
+
# parameters:
|
| 73 |
+
# t:
|
| 74 |
+
# # Trượt dốc từ 10% (đáy) lên 90% (đỉnh)
|
| 75 |
+
# - value: [0.1, 0.3, 0.5, 0.7, 0.9]
|
| 76 |
+
# dtype: bfloat16
|
| 77 |
+
```
|
__pycache__/llama_bidirectional_model.cpython-312.pyc
ADDED
|
Binary file (9.14 kB). View file
|
|
|
config.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LlamaBidirectionalModel"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"auto_map": {
|
| 8 |
+
"AutoConfig": "llama_bidirectional_model.LlamaBidirectionalConfig",
|
| 9 |
+
"AutoModel": "llama_bidirectional_model.LlamaBidirectionalModel"
|
| 10 |
+
},
|
| 11 |
+
"bos_token_id": 128000,
|
| 12 |
+
"dtype": "bfloat16",
|
| 13 |
+
"eos_token_id": 128001,
|
| 14 |
+
"head_dim": 64,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"hidden_size": 2048,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 8192,
|
| 19 |
+
"max_position_embeddings": 131072,
|
| 20 |
+
"mlp_bias": false,
|
| 21 |
+
"model_type": "llama_bidirec",
|
| 22 |
+
"num_attention_heads": 32,
|
| 23 |
+
"num_hidden_layers": 16,
|
| 24 |
+
"num_key_value_heads": 8,
|
| 25 |
+
"pad_token_id": null,
|
| 26 |
+
"pooling": "avg",
|
| 27 |
+
"pretraining_tp": 1,
|
| 28 |
+
"quantization_config": {
|
| 29 |
+
"quant_method": "quanto",
|
| 30 |
+
"weights": "int8"
|
| 31 |
+
},
|
| 32 |
+
"rms_norm_eps": 1e-05,
|
| 33 |
+
"rope_parameters": {
|
| 34 |
+
"factor": 32.0,
|
| 35 |
+
"high_freq_factor": 4.0,
|
| 36 |
+
"low_freq_factor": 1.0,
|
| 37 |
+
"original_max_position_embeddings": 8192,
|
| 38 |
+
"rope_theta": 500000.0,
|
| 39 |
+
"rope_type": "llama3"
|
| 40 |
+
},
|
| 41 |
+
"temperature": 1.0,
|
| 42 |
+
"tie_word_embeddings": true,
|
| 43 |
+
"transformers_version": "5.14.1",
|
| 44 |
+
"use_bidirectional_attention": true,
|
| 45 |
+
"use_cache": true,
|
| 46 |
+
"vocab_size": 128256
|
| 47 |
+
}
|
config_1.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LlamaModel"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 128000,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": 128001,
|
| 10 |
+
"head_dim": 64,
|
| 11 |
+
"hidden_act": "silu",
|
| 12 |
+
"hidden_size": 2048,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 8192,
|
| 15 |
+
"max_position_embeddings": 131072,
|
| 16 |
+
"mlp_bias": false,
|
| 17 |
+
"model_type": "llama",
|
| 18 |
+
"num_attention_heads": 32,
|
| 19 |
+
"num_hidden_layers": 16,
|
| 20 |
+
"num_key_value_heads": 8,
|
| 21 |
+
"pad_token_id": 128001,
|
| 22 |
+
"pooling": "avg",
|
| 23 |
+
"pretraining_tp": 1,
|
| 24 |
+
"rms_norm_eps": 1e-05,
|
| 25 |
+
"rope_parameters": {
|
| 26 |
+
"factor": 32.0,
|
| 27 |
+
"high_freq_factor": 4.0,
|
| 28 |
+
"low_freq_factor": 1.0,
|
| 29 |
+
"original_max_position_embeddings": 8192,
|
| 30 |
+
"rope_theta": 500000.0,
|
| 31 |
+
"rope_type": "llama3"
|
| 32 |
+
},
|
| 33 |
+
"rope_scaling": null,
|
| 34 |
+
"rope_theta": 10000.0,
|
| 35 |
+
"tie_word_embeddings": true,
|
| 36 |
+
"transformers_version": "4.56.0",
|
| 37 |
+
"use_bidirectional_attention": true,
|
| 38 |
+
"use_cache": false,
|
| 39 |
+
"vocab_size": 128256
|
| 40 |
+
}
|
config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "SentenceTransformer",
|
| 3 |
+
"__version__": {
|
| 4 |
+
"sentence_transformers": "5.0.1",
|
| 5 |
+
"transformers": "4.47.1",
|
| 6 |
+
"pytorch": "2.9.1+cu126"
|
| 7 |
+
},
|
| 8 |
+
"prompts": {
|
| 9 |
+
"query": "query: ",
|
| 10 |
+
"document": "passage: "
|
| 11 |
+
},
|
| 12 |
+
"default_prompt_name": null,
|
| 13 |
+
"similarity_fn_name": "cosine"
|
| 14 |
+
}
|
llama_bidirectional_model.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0.
|
| 3 |
+
"""
|
| 4 |
+
Bidirectional Llama model for embedding tasks.
|
| 5 |
+
|
| 6 |
+
This module provides a modified LlamaModel that uses bidirectional (non-causal)
|
| 7 |
+
attention, suitable for generating embeddings where each token should attend
|
| 8 |
+
to all other tokens in the sequence.
|
| 9 |
+
|
| 10 |
+
Supports transformers version 4.44 and above with a unified forward() implementation.
|
| 11 |
+
|
| 12 |
+
Version compatibility notes:
|
| 13 |
+
- transformers 4.47: Setting _attn_implementation in __init__ had no effect due to
|
| 14 |
+
attention initialization order
|
| 15 |
+
- transformers 4.48+: Attention refactor (transformers#35235) activated the
|
| 16 |
+
_attn_implementation setting, which defaulted to "eager" instead of "sdpa"
|
| 17 |
+
- transformers < 4.53: LlamaModel has _update_causal_mask method that can be overridden
|
| 18 |
+
- transformers 4.53+: _update_causal_mask removed; masking moved to masking_utils module,
|
| 19 |
+
necessitating a full forward() override for custom attention masks
|
| 20 |
+
- transformers < 4.54: Decoder layer returns tuple, uses past_key_value (singular)
|
| 21 |
+
- transformers 4.54-4.55: Decoder layer returns tensor, uses past_key_value (singular)
|
| 22 |
+
- transformers 4.56+: Decoder layer returns tensor, uses past_key_values (plural),
|
| 23 |
+
DynamicCache accepts config parameter
|
| 24 |
+
- transformers 5.0+: Has native create_bidirectional_mask in masking_utils
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
import inspect
|
| 28 |
+
|
| 29 |
+
import torch
|
| 30 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 31 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast
|
| 32 |
+
from transformers.models.llama.configuration_llama import LlamaConfig
|
| 33 |
+
from transformers.models.llama.modeling_llama import LlamaDecoderLayer, LlamaModel
|
| 34 |
+
from transformers.utils import logging
|
| 35 |
+
|
| 36 |
+
logger = logging.get_logger(__name__)
|
| 37 |
+
|
| 38 |
+
# Check if native create_bidirectional_mask exists (transformers >= 5.0)
|
| 39 |
+
try:
|
| 40 |
+
from transformers.masking_utils import create_bidirectional_mask
|
| 41 |
+
|
| 42 |
+
_HAS_NATIVE_BIDIRECTIONAL_MASK = True
|
| 43 |
+
except ImportError:
|
| 44 |
+
from transformers.modeling_attn_mask_utils import _prepare_4d_attention_mask
|
| 45 |
+
|
| 46 |
+
_HAS_NATIVE_BIDIRECTIONAL_MASK = False
|
| 47 |
+
|
| 48 |
+
# Detect API differences via introspection
|
| 49 |
+
_decoder_forward_params = inspect.signature(LlamaDecoderLayer.forward).parameters
|
| 50 |
+
_dynamic_cache_init_params = inspect.signature(DynamicCache.__init__).parameters
|
| 51 |
+
|
| 52 |
+
# past_key_value (singular) in < 4.56, past_key_values (plural) in >= 4.56
|
| 53 |
+
_USE_PLURAL_CACHE_PARAM = "past_key_values" in _decoder_forward_params
|
| 54 |
+
# DynamicCache accepts config parameter in >= 4.56
|
| 55 |
+
_DYNAMIC_CACHE_ACCEPTS_CONFIG = "config" in _dynamic_cache_init_params
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class LlamaBidirectionalConfig(LlamaConfig):
|
| 59 |
+
"""Configuration for LlamaBidirectionalModel with pooling and temperature settings."""
|
| 60 |
+
|
| 61 |
+
model_type = "llama_bidirec"
|
| 62 |
+
|
| 63 |
+
def __init__(
|
| 64 |
+
self, pooling: str = "avg", temperature: float = 1.0, **kwargs
|
| 65 |
+
) -> None:
|
| 66 |
+
"""
|
| 67 |
+
Initialize bidirectional Llama configuration.
|
| 68 |
+
|
| 69 |
+
Args:
|
| 70 |
+
pooling: Pooling strategy for embeddings ("avg", "cls", "last", etc.)
|
| 71 |
+
temperature: Temperature scaling for embeddings
|
| 72 |
+
**kwargs: Additional arguments passed to LlamaConfig
|
| 73 |
+
"""
|
| 74 |
+
self.pooling = pooling
|
| 75 |
+
self.temperature = temperature
|
| 76 |
+
super().__init__(**kwargs)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class LlamaBidirectionalModel(LlamaModel):
|
| 80 |
+
"""
|
| 81 |
+
LlamaModel modified to use bidirectional (non-causal) attention.
|
| 82 |
+
|
| 83 |
+
In standard Llama, each token can only attend to previous tokens (causal attention).
|
| 84 |
+
This model removes that restriction, allowing each token to attend to all tokens
|
| 85 |
+
in the sequence, which is useful for embedding tasks.
|
| 86 |
+
|
| 87 |
+
The key modifications are:
|
| 88 |
+
1. Setting is_causal=False on all attention layers
|
| 89 |
+
2. Using a bidirectional attention mask instead of causal mask
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
config_class = LlamaBidirectionalConfig
|
| 93 |
+
|
| 94 |
+
def __init__(self, config: LlamaConfig) -> None:
|
| 95 |
+
super().__init__(config)
|
| 96 |
+
for layer in self.layers:
|
| 97 |
+
layer.self_attn.is_causal = False
|
| 98 |
+
|
| 99 |
+
def _create_bidirectional_mask(
|
| 100 |
+
self,
|
| 101 |
+
input_embeds: torch.Tensor,
|
| 102 |
+
attention_mask: torch.Tensor | None,
|
| 103 |
+
) -> torch.Tensor | None:
|
| 104 |
+
"""
|
| 105 |
+
Create bidirectional attention mask.
|
| 106 |
+
|
| 107 |
+
Args:
|
| 108 |
+
input_embeds: Input embeddings tensor of shape (batch_size, seq_len, hidden_size)
|
| 109 |
+
attention_mask: Optional 2D attention mask of shape (batch_size, seq_len)
|
| 110 |
+
where 1 indicates tokens to attend to and 0 indicates masked tokens
|
| 111 |
+
|
| 112 |
+
Returns:
|
| 113 |
+
4D attention mask suitable for the attention implementation, or None
|
| 114 |
+
if no masking is needed
|
| 115 |
+
"""
|
| 116 |
+
if attention_mask is None:
|
| 117 |
+
return None
|
| 118 |
+
|
| 119 |
+
if _HAS_NATIVE_BIDIRECTIONAL_MASK:
|
| 120 |
+
return create_bidirectional_mask(
|
| 121 |
+
config=self.config,
|
| 122 |
+
input_embeds=input_embeds,
|
| 123 |
+
attention_mask=attention_mask,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
# Fallback for transformers < 5.0 without create_bidirectional_mask
|
| 127 |
+
|
| 128 |
+
# Flash attention handles 2D masks internally; only pass mask if there
|
| 129 |
+
# are actually masked tokens (zeros), otherwise return None for efficiency
|
| 130 |
+
if getattr(self.config, "_attn_implementation", None) == "flash_attention_2":
|
| 131 |
+
has_masked_tokens = (attention_mask == 0).any()
|
| 132 |
+
return attention_mask if has_masked_tokens else None
|
| 133 |
+
|
| 134 |
+
return _prepare_4d_attention_mask(attention_mask, input_embeds.dtype)
|
| 135 |
+
|
| 136 |
+
def forward(
|
| 137 |
+
self,
|
| 138 |
+
input_ids: torch.LongTensor | None = None,
|
| 139 |
+
attention_mask: torch.Tensor | None = None,
|
| 140 |
+
position_ids: torch.LongTensor | None = None,
|
| 141 |
+
past_key_values: Cache | None = None,
|
| 142 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 143 |
+
cache_position: torch.LongTensor | None = None,
|
| 144 |
+
use_cache: bool | None = None,
|
| 145 |
+
**kwargs,
|
| 146 |
+
) -> BaseModelOutputWithPast:
|
| 147 |
+
"""
|
| 148 |
+
Forward pass with bidirectional attention.
|
| 149 |
+
|
| 150 |
+
Args:
|
| 151 |
+
input_ids: Input token IDs of shape (batch_size, seq_len)
|
| 152 |
+
attention_mask: Attention mask of shape (batch_size, seq_len)
|
| 153 |
+
position_ids: Position IDs for rotary embeddings
|
| 154 |
+
past_key_values: Cached key/value states for incremental decoding
|
| 155 |
+
inputs_embeds: Pre-computed input embeddings (alternative to input_ids)
|
| 156 |
+
cache_position: Position indices for cache updates
|
| 157 |
+
use_cache: Whether to return cached key/value states
|
| 158 |
+
**kwargs: Additional arguments passed to decoder layers
|
| 159 |
+
|
| 160 |
+
Returns:
|
| 161 |
+
BaseModelOutputWithPast containing last_hidden_state and past_key_values
|
| 162 |
+
"""
|
| 163 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 164 |
+
raise ValueError(
|
| 165 |
+
"You must specify exactly one of input_ids or inputs_embeds"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
if inputs_embeds is None:
|
| 169 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 170 |
+
|
| 171 |
+
# Initialize cache if needed
|
| 172 |
+
if use_cache and past_key_values is None:
|
| 173 |
+
if _DYNAMIC_CACHE_ACCEPTS_CONFIG:
|
| 174 |
+
past_key_values = DynamicCache(config=self.config)
|
| 175 |
+
else:
|
| 176 |
+
past_key_values = DynamicCache()
|
| 177 |
+
|
| 178 |
+
if cache_position is None:
|
| 179 |
+
past_seen_tokens = (
|
| 180 |
+
past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 181 |
+
)
|
| 182 |
+
cache_position = torch.arange(
|
| 183 |
+
past_seen_tokens,
|
| 184 |
+
past_seen_tokens + inputs_embeds.shape[1],
|
| 185 |
+
device=inputs_embeds.device,
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
if position_ids is None:
|
| 189 |
+
position_ids = cache_position.unsqueeze(0)
|
| 190 |
+
|
| 191 |
+
bidirectional_mask = self._create_bidirectional_mask(
|
| 192 |
+
inputs_embeds, attention_mask
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
hidden_states = inputs_embeds
|
| 196 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 197 |
+
|
| 198 |
+
# Build decoder layer kwargs with correct cache parameter name
|
| 199 |
+
# (past_key_value in < 4.56, past_key_values in >= 4.56)
|
| 200 |
+
layer_kwargs = {
|
| 201 |
+
"attention_mask": bidirectional_mask,
|
| 202 |
+
"position_ids": position_ids,
|
| 203 |
+
"use_cache": use_cache,
|
| 204 |
+
"cache_position": cache_position,
|
| 205 |
+
"position_embeddings": position_embeddings,
|
| 206 |
+
}
|
| 207 |
+
if _USE_PLURAL_CACHE_PARAM:
|
| 208 |
+
layer_kwargs["past_key_values"] = past_key_values
|
| 209 |
+
else:
|
| 210 |
+
layer_kwargs["past_key_value"] = past_key_values
|
| 211 |
+
|
| 212 |
+
for decoder_layer in self.layers[: self.config.num_hidden_layers]:
|
| 213 |
+
layer_outputs = decoder_layer(hidden_states, **layer_kwargs)
|
| 214 |
+
|
| 215 |
+
# Decoder returns tuple in < 4.54, tensor in >= 4.54
|
| 216 |
+
if isinstance(layer_outputs, tuple):
|
| 217 |
+
hidden_states = layer_outputs[0]
|
| 218 |
+
else:
|
| 219 |
+
hidden_states = layer_outputs
|
| 220 |
+
|
| 221 |
+
hidden_states = self.norm(hidden_states)
|
| 222 |
+
|
| 223 |
+
return BaseModelOutputWithPast(
|
| 224 |
+
last_hidden_state=hidden_states,
|
| 225 |
+
past_key_values=past_key_values,
|
| 226 |
+
)
|
mergekit_config.yml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# slices:
|
| 2 |
+
# - sources:
|
| 3 |
+
# - model: psmathur/orca_mini_v3_13b
|
| 4 |
+
# layer_range: [0, 40]
|
| 5 |
+
# - model: garage-bAInd/Platypus2-13B
|
| 6 |
+
# layer_range: [0, 40]
|
| 7 |
+
# # or, the equivalent models: syntax:
|
| 8 |
+
# # models:
|
| 9 |
+
# # - model: psmathur/orca_mini_v3_13b
|
| 10 |
+
# # - model: garage-bAInd/Platypus2-13B
|
| 11 |
+
# merge_method: slerp
|
| 12 |
+
# base_model: psmathur/orca_mini_v3_13b
|
| 13 |
+
# parameters:
|
| 14 |
+
# t:
|
| 15 |
+
# - filter: self_attn
|
| 16 |
+
# value: [0, 0.5, 0.3, 0.7, 1]
|
| 17 |
+
# - filter: mlp
|
| 18 |
+
# value: [1, 0.5, 0.7, 0.3, 0]
|
| 19 |
+
# - value: 0.5 # fallback for rest of tensors
|
| 20 |
+
# dtype: float16
|
| 21 |
+
# slices:
|
| 22 |
+
models:
|
| 23 |
+
- model: /workspace/storage-shared/cnm/embedding/code/llama_1B_legal_retrieval_v2_2.3M_clean_150726_finetune2_07150726/checkpoint-8000 # Mô hình A (Base gốc)
|
| 24 |
+
# layer_range: [0, 36]
|
| 25 |
+
- model: /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6 # Mô hình B (Đã Finetune)
|
| 26 |
+
# layer_range: [0, 36]
|
| 27 |
+
merge_method: slerp
|
| 28 |
+
base_model: /workspace/storage-shared/cnm/huyhq21_v2/mergekit/output_slerp_1B_data_v2_clean_v6 # Mô hình B (Đã Finetune)
|
| 29 |
+
parameters:
|
| 30 |
+
t:
|
| 31 |
+
#- filter: self_attn
|
| 32 |
+
- filter: layers
|
| 33 |
+
value: [0.2, 0.3, 0.5, 0.6, 0.7, 0.8]
|
| 34 |
+
#- filter: mlp
|
| 35 |
+
# value: [0.2, 0.3, 0.5, 0.6, 0.7, 0.8]
|
| 36 |
+
- value: 0.5 # fallback cho layernorm
|
| 37 |
+
dtype: bfloat16
|
| 38 |
+
|
| 39 |
+
# models:
|
| 40 |
+
# - model: /workspace/storage-shared/cnm/cuongnq23/project_embeding/models/Qwen/Qwen3-Embedding-8B
|
| 41 |
+
# - model: /workspace/storage-shared/cnm/embedding/code/qwen8b_SFT_kalm_vnlaw_3M/checkpoint-20000
|
| 42 |
+
# merge_method: slerp
|
| 43 |
+
# base_model: /workspace/storage-shared/cnm/cuongnq23/project_embeding/models/Qwen/Qwen3-Embedding-8B
|
| 44 |
+
# parameters:
|
| 45 |
+
# t:
|
| 46 |
+
# # Trượt dốc từ 10% (đáy) lên 90% (đỉnh)
|
| 47 |
+
# - value: [0.1, 0.3, 0.5, 0.7, 0.9]
|
| 48 |
+
# dtype: bfloat16
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:79b68957119a1ba2974b5b2846956975657c6c375c9ba47ee70ee76c59a091cf
|
| 3 |
+
size 1499356520
|
modules.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"idx": 0,
|
| 4 |
+
"name": "0",
|
| 5 |
+
"path": "",
|
| 6 |
+
"type": "sentence_transformers.models.Transformer"
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"idx": 1,
|
| 10 |
+
"name": "1",
|
| 11 |
+
"path": "1_Pooling",
|
| 12 |
+
"type": "sentence_transformers.models.Pooling"
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"idx": 2,
|
| 16 |
+
"name": "2",
|
| 17 |
+
"path": "2_Normalize",
|
| 18 |
+
"type": "sentence_transformers.models.Normalize"
|
| 19 |
+
}
|
| 20 |
+
]
|
pooling.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0.
|
| 3 |
+
from torch import Tensor
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def pool(last_hidden_states: Tensor, attention_mask: Tensor, pool_type: str) -> Tensor:
|
| 8 |
+
last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
|
| 9 |
+
|
| 10 |
+
if pool_type == "avg":
|
| 11 |
+
emb = last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
|
| 12 |
+
elif pool_type == "weighted_avg":
|
| 13 |
+
emb = last_hidden.sum(dim=1)
|
| 14 |
+
elif pool_type == "cls":
|
| 15 |
+
emb = last_hidden[:, 0]
|
| 16 |
+
elif pool_type == "last":
|
| 17 |
+
left_padding = attention_mask[:, -1].sum() == attention_mask.shape[0]
|
| 18 |
+
if left_padding:
|
| 19 |
+
emb = last_hidden[:, -1]
|
| 20 |
+
else:
|
| 21 |
+
sequence_lengths = attention_mask.sum(dim=1) - 1
|
| 22 |
+
batch_size = last_hidden.shape[0]
|
| 23 |
+
emb = last_hidden[
|
| 24 |
+
torch.arange(batch_size, device=last_hidden.device), sequence_lengths
|
| 25 |
+
]
|
| 26 |
+
else:
|
| 27 |
+
raise ValueError(f"pool_type {pool_type} not supported")
|
| 28 |
+
|
| 29 |
+
return emb
|
sentence_bert_config.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"max_seq_length": 8192,
|
| 3 |
+
"do_lower_case": false
|
| 4 |
+
}
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<|begin_of_text|>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "<|end_of_text|>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "<|end_of_text|>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
}
|
| 23 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cb956fd3e742594d4410fdb86df5edf0c1b0f1f382117a2fbd877f2372ec158d
|
| 3 |
+
size 17210019
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<|begin_of_text|>",
|
| 4 |
+
"clean_up_tokenization_spaces": true,
|
| 5 |
+
"eos_token": "<|end_of_text|>",
|
| 6 |
+
"is_local": true,
|
| 7 |
+
"local_files_only": false,
|
| 8 |
+
"max_length": 8192,
|
| 9 |
+
"model_input_names": [
|
| 10 |
+
"input_ids",
|
| 11 |
+
"attention_mask"
|
| 12 |
+
],
|
| 13 |
+
"model_max_length": 131072,
|
| 14 |
+
"pad_token": "<|end_of_text|>",
|
| 15 |
+
"stride": 0,
|
| 16 |
+
"tokenizer_class": "TokenizersBackend",
|
| 17 |
+
"truncation_side": "right",
|
| 18 |
+
"truncation_strategy": "longest_first"
|
| 19 |
+
}
|