Text Generation
MLX
Safetensors
English
k2_horizon
mlx-lm
4-bit precision
k2-horizon
long-context
512k-context
dense
conversational
custom_code
Instructions to use abenzerps/K2-Horizon-3.7B-MLX-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use abenzerps/K2-Horizon-3.7B-MLX-4bit with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("abenzerps/K2-Horizon-3.7B-MLX-4bit") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use abenzerps/K2-Horizon-3.7B-MLX-4bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "abenzerps/K2-Horizon-3.7B-MLX-4bit"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "abenzerps/K2-Horizon-3.7B-MLX-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use abenzerps/K2-Horizon-3.7B-MLX-4bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "abenzerps/K2-Horizon-3.7B-MLX-4bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "abenzerps/K2-Horizon-3.7B-MLX-4bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "abenzerps/K2-Horizon-3.7B-MLX-4bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use abenzerps/K2-Horizon-3.7B-MLX-4bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "abenzerps/K2-Horizon-3.7B-MLX-4bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default abenzerps/K2-Horizon-3.7B-MLX-4bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use abenzerps/K2-Horizon-3.7B-MLX-4bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "abenzerps/K2-Horizon-3.7B-MLX-4bit"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "abenzerps/K2-Horizon-3.7B-MLX-4bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Commit ·
016adec
0
Parent(s):
K2-Horizon-3.7B MLX 4-bit release
Browse files- .gitattributes +37 -0
- README.md +53 -0
- SHA256SUMS.txt +11 -0
- assets/k2-horizon-3.7b-benchmarks.png +3 -0
- chat_template.jinja +994 -0
- config.json +104 -0
- configuration_k2_horizon.py +96 -0
- generation_config.json +7 -0
- k2_horizon_mlx.py +198 -0
- model.safetensors +3 -0
- model.safetensors.index.json +843 -0
- modeling_k2_horizon.py +1116 -0
- tokenizer.json +3 -0
- tokenizer_config.json +10 -0
.gitattributes
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz 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 |
+
assets/k2-horizon-3.7b-benchmarks.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: IFM/K2-Horizon-3.7B
|
| 3 |
+
base_model_relation: quantized
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
library_name: mlx
|
| 9 |
+
tags:
|
| 10 |
+
- mlx
|
| 11 |
+
- mlx-lm
|
| 12 |
+
- 4-bit
|
| 13 |
+
- k2-horizon
|
| 14 |
+
- long-context
|
| 15 |
+
- 512k-context
|
| 16 |
+
- dense
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# K2-Horizon-3.7B MLX — 4-bit
|
| 20 |
+
|
| 21 |
+
MLX 4-bit conversion of [IFM/K2-Horizon-3.7B](https://huggingface.co/IFM/K2-Horizon-3.7B), a 3.7B dense decoder-only model for reasoning, coding, long-context work, and tool use. The source checkpoint supports a native context length of **524,288 tokens (512K)**.
|
| 22 |
+
|
| 23 |
+
## Benchmarks
|
| 24 |
+
|
| 25 |
+

|
| 26 |
+
|
| 27 |
+
*Benchmark results reported by IFM for the original IFM/K2-Horizon-3.7B checkpoint.*
|
| 28 |
+
|
| 29 |
+
## Release
|
| 30 |
+
|
| 31 |
+
| Format | Quantization | Size |
|
| 32 |
+
| --- | --- | ---: |
|
| 33 |
+
| MLX safetensors | Affine 4-bit, group size 64 | 2.87 GB |
|
| 34 |
+
|
| 35 |
+
The included `k2_horizon_mlx.py` adapter preserves K2 Horizon's grouped RMSNorm. Use it with MLX-LM and `--trust-remote-code`. The model is text-only; no vision projector or MTP files are included.
|
| 36 |
+
|
| 37 |
+
## Usage
|
| 38 |
+
|
| 39 |
+
```bash
|
| 40 |
+
pip install -U mlx-lm
|
| 41 |
+
mlx_lm.generate \
|
| 42 |
+
--model . \
|
| 43 |
+
--trust-remote-code \
|
| 44 |
+
--prompt "Explain why reproducible builds matter." \
|
| 45 |
+
--max-tokens 512
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
## Source
|
| 49 |
+
|
| 50 |
+
- Model: [IFM/K2-Horizon-3.7B](https://huggingface.co/IFM/K2-Horizon-3.7B)
|
| 51 |
+
- Source revision: [`633f52a`](https://huggingface.co/IFM/K2-Horizon-3.7B/tree/633f52ad28b17edeabd82afc61d2d13b4c59a561)
|
| 52 |
+
- License: [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 53 |
+
- Checksums: [SHA256SUMS.txt](SHA256SUMS.txt)
|
SHA256SUMS.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
0d8e479c380d5d9c8b28ea753205dd9736e53682aaf0038962088cd27c08a0d0 README.md
|
| 2 |
+
a892cd0b0195599f283a8c706787520d9a6747640efb2f4dec4144b0abb62590 chat_template.jinja
|
| 3 |
+
fec604c00546023bc73b9c00f7aa594831839e9db47ff2f25c288825cbeac1b1 config.json
|
| 4 |
+
5c2f993c1053d9462ebea6dea416c897fddfbb4a5edd904e486936b20d4badc5 configuration_k2_horizon.py
|
| 5 |
+
2da7d47641f4509da4ae47711e31d8b5f0f3f801ee08d87e7e9f07f814bdc4a3 generation_config.json
|
| 6 |
+
56c88b1f4ece81dc946a0b8a2431822aaa67f0ff45c04496d683697c0cb5fef9 k2_horizon_mlx.py
|
| 7 |
+
f2155c94d950cbc6d55929b0e46b114a912e211d006ae89bc7ed987b4b1cd2e8 model.safetensors
|
| 8 |
+
0328a4fa1d70bdea50b7e747286e52ada17c145a142fa2cdfe5c944abe91c521 model.safetensors.index.json
|
| 9 |
+
fb09e010956bd51cfa7d4055b4381cff34c9e06164066b49e3546f38b2e6242f modeling_k2_horizon.py
|
| 10 |
+
838d767b7c9925ff257feb20eaa4299a8e3cc35bb3d805589c373f51d2cc3cb6 tokenizer.json
|
| 11 |
+
068cfdcf2bcef44fd77f935a9fb41b4d45af547fd41b95079817bd40b24fe518 tokenizer_config.json
|
assets/k2-horizon-3.7b-benchmarks.png
ADDED
|
Git LFS Details
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,994 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{{- bos_token }}
|
| 2 |
+
{%- if tool_presentation is defined -%}
|
| 3 |
+
{{- raise_exception("Unsupported argument: tool_presentation. Use tool_presentation_format with one of: json, xml, markdown.") -}}
|
| 4 |
+
{%- endif -%}
|
| 5 |
+
{%- if tool_calling_format is defined -%}
|
| 6 |
+
{{- raise_exception("Unsupported argument: tool_calling_format. Use tool_call_format with one of: json, xml, xml_typed.") -}}
|
| 7 |
+
{%- endif -%}
|
| 8 |
+
{%- if tool_format is defined -%}
|
| 9 |
+
{{- raise_exception("Unsupported argument: tool_format. Use tool_call_format with one of: json, xml, xml_typed.") -}}
|
| 10 |
+
{%- endif -%}
|
| 11 |
+
{%- set tool_presentation_fmt = tool_presentation_format | default('markdown') -%}
|
| 12 |
+
{%- set tool_call_fmt = tool_call_format | default('xml') -%}
|
| 13 |
+
{%- if tool_presentation_fmt != 'json' and tool_presentation_fmt != 'xml' and tool_presentation_fmt != 'markdown' -%}
|
| 14 |
+
{{- raise_exception("Unsupported tool_presentation_format: '" ~ tool_presentation_fmt ~ "'. Supported formats: json, xml, markdown.") -}}
|
| 15 |
+
{%- endif -%}
|
| 16 |
+
{%- if tool_call_fmt != 'json' and tool_call_fmt != 'xml' and tool_call_fmt != 'xml_typed' -%}
|
| 17 |
+
{{- raise_exception("Unsupported tool_call_format: '" ~ tool_call_fmt ~ "'. Supported formats: json, xml, xml_typed.") -}}
|
| 18 |
+
{%- endif -%}
|
| 19 |
+
|
| 20 |
+
{#- Renderability state, computed during validate_tools (single walk, no extra -#}
|
| 21 |
+
{#- traversal at render time): ok = working flag for the tool being validated; -#}
|
| 22 |
+
{#- bad = pipe-delimited indices of tools that must render as verbatim JSON. -#}
|
| 23 |
+
{%- set RB = namespace(ok=true, bad='|') -%}
|
| 24 |
+
|
| 25 |
+
{%- macro value_contains_mapping(v) -%}
|
| 26 |
+
{%- if v is mapping -%}
|
| 27 |
+
true
|
| 28 |
+
{%- elif v is sequence and v is not string -%}
|
| 29 |
+
{%- set f = namespace(x='false') -%}
|
| 30 |
+
{%- for c in v -%}{%- if value_contains_mapping(c) == 'true' -%}{%- set f.x = 'true' -%}{%- endif -%}{%- endfor -%}
|
| 31 |
+
{{- f.x -}}
|
| 32 |
+
{%- else -%}
|
| 33 |
+
false
|
| 34 |
+
{%- endif -%}
|
| 35 |
+
{%- endmacro -%}
|
| 36 |
+
|
| 37 |
+
{#- $ref inlining state: defs = local $defs of the tool being rendered; seen = -#}
|
| 38 |
+
{#- pipe-delimited names already expanded for this tool (each def inlines at most -#}
|
| 39 |
+
{#- once; later references render by def name; cycles terminate immediately). -#}
|
| 40 |
+
{#- $ref-sibling annotations (description/default/...) merge OVER the def at -#}
|
| 41 |
+
{#- the inline site, so use-site annotations win and are never dropped. -#}
|
| 42 |
+
{%- set REFS = namespace(defs={}, seen='|') -%}
|
| 43 |
+
|
| 44 |
+
{%- macro render_compact_type_name(type_name, spec) -%}
|
| 45 |
+
{%- if type_name == "array" -%}
|
| 46 |
+
array[{%- if 'items' in spec -%}{{ render_compact_type(spec['items']) }}{%- else -%}any{%- endif -%}]
|
| 47 |
+
{%- elif type_name -%}
|
| 48 |
+
{{- type_name -}}
|
| 49 |
+
{%- else -%}
|
| 50 |
+
any
|
| 51 |
+
{%- endif -%}
|
| 52 |
+
{%- endmacro -%}
|
| 53 |
+
|
| 54 |
+
{%- macro render_compact_type(spec) -%}
|
| 55 |
+
{%- if spec is not mapping -%}
|
| 56 |
+
any
|
| 57 |
+
{%- elif spec.type is defined and spec.type is sequence and spec.type is not string and spec.type | length > 0 -%}
|
| 58 |
+
{%- for type_name in spec.type -%}{{ render_compact_type_name(type_name, spec) }}{%- if not loop.last -%}|{%- endif -%}{%- endfor -%}
|
| 59 |
+
{%- elif spec.type is defined and spec.type is sequence and spec.type is not string -%}
|
| 60 |
+
any
|
| 61 |
+
{%- elif spec.type -%}
|
| 62 |
+
{{- render_compact_type_name(spec.type, spec) -}}
|
| 63 |
+
{%- elif spec['$ref'] is string -%}
|
| 64 |
+
{{- spec['$ref'].split('/') | last -}}
|
| 65 |
+
{%- elif spec.oneOf -%}
|
| 66 |
+
oneOf[{%- for variant in spec.oneOf -%}{{ render_compact_type(variant) }}{%- if not loop.last -%}|{%- endif -%}{%- endfor -%}]
|
| 67 |
+
{%- elif spec.anyOf -%}
|
| 68 |
+
anyOf[{%- for variant in spec.anyOf -%}{{ render_compact_type(variant) }}{%- if not loop.last -%}|{%- endif -%}{%- endfor -%}]
|
| 69 |
+
{%- elif spec.properties -%}
|
| 70 |
+
object
|
| 71 |
+
{%- elif 'items' in spec -%}
|
| 72 |
+
array[{{ render_compact_type(spec['items']) }}]
|
| 73 |
+
{%- else -%}
|
| 74 |
+
any
|
| 75 |
+
{%- endif -%}
|
| 76 |
+
{%- endmacro -%}
|
| 77 |
+
|
| 78 |
+
{%- macro render_markdown_type_name(type_name, spec) -%}
|
| 79 |
+
{%- if type_name == "array" -%}
|
| 80 |
+
array of {% if 'items' in spec %}{{ render_markdown_type(spec['items']) }}{% else %}any{% endif %}
|
| 81 |
+
{%- elif type_name -%}
|
| 82 |
+
{{- type_name -}}
|
| 83 |
+
{%- else -%}
|
| 84 |
+
any
|
| 85 |
+
{%- endif -%}
|
| 86 |
+
{%- endmacro -%}
|
| 87 |
+
|
| 88 |
+
{%- macro render_markdown_type(spec) -%}
|
| 89 |
+
{%- if spec is sameas true -%}
|
| 90 |
+
True
|
| 91 |
+
{%- elif spec is sameas false -%}
|
| 92 |
+
False
|
| 93 |
+
{%- elif spec is not mapping -%}
|
| 94 |
+
any
|
| 95 |
+
{%- elif spec.type is defined and spec.type is sequence and spec.type is not string and spec.type | length > 0 -%}
|
| 96 |
+
{%- for type_name in spec.type -%}{{ render_markdown_type_name(type_name, spec) }}{% if not loop.last %} or {% endif %}{%- endfor -%}
|
| 97 |
+
{%- elif spec.type is defined and spec.type is sequence and spec.type is not string -%}
|
| 98 |
+
any
|
| 99 |
+
{%- elif spec.type -%}
|
| 100 |
+
{{- render_markdown_type_name(spec.type, spec) -}}
|
| 101 |
+
{%- elif spec['$ref'] is string -%}
|
| 102 |
+
{{- spec['$ref'].split('/') | last -}}
|
| 103 |
+
{%- elif spec.oneOf -%}
|
| 104 |
+
oneOf[{%- for variant in spec.oneOf -%}{{ render_markdown_type(variant) }}{% if not loop.last %} or {% endif %}{%- endfor -%}]
|
| 105 |
+
{%- elif spec.anyOf -%}
|
| 106 |
+
anyOf[{%- for variant in spec.anyOf -%}{{ render_markdown_type(variant) }}{% if not loop.last %} or {% endif %}{%- endfor -%}]
|
| 107 |
+
{%- elif spec.properties -%}
|
| 108 |
+
object
|
| 109 |
+
{%- elif 'items' in spec -%}
|
| 110 |
+
array of {{ render_markdown_type(spec['items']) }}
|
| 111 |
+
{%- else -%}
|
| 112 |
+
any
|
| 113 |
+
{%- endif -%}
|
| 114 |
+
{%- endmacro -%}
|
| 115 |
+
|
| 116 |
+
{%- macro render_xml_text(value) -%}
|
| 117 |
+
{{- value.split() | join(" ") -}}
|
| 118 |
+
{%- endmacro -%}
|
| 119 |
+
|
| 120 |
+
{%- macro render_python_string(value) -%}
|
| 121 |
+
'{{- value.split() | join(" ") | replace("\\", "\\\\") | replace("'", "\\'") -}}'
|
| 122 |
+
{%- endmacro -%}
|
| 123 |
+
|
| 124 |
+
{%- macro render_python_repr(value) -%}
|
| 125 |
+
{%- if value is string -%}
|
| 126 |
+
{{ render_python_string(value) }}
|
| 127 |
+
{%- elif value is sameas true -%}
|
| 128 |
+
True
|
| 129 |
+
{%- elif value is sameas false -%}
|
| 130 |
+
False
|
| 131 |
+
{%- elif value is none -%}
|
| 132 |
+
None
|
| 133 |
+
{%- elif value is mapping -%}
|
| 134 |
+
{{- "{" -}}
|
| 135 |
+
{%- for key, child in value | items -%}
|
| 136 |
+
{{ render_python_repr(key) }}: {{ render_python_repr(child) }}{%- if not loop.last -%}, {% endif -%}
|
| 137 |
+
{%- endfor -%}
|
| 138 |
+
{{- "}" -}}
|
| 139 |
+
{%- elif value is sequence -%}
|
| 140 |
+
{{- "[" -}}
|
| 141 |
+
{%- for child in value -%}
|
| 142 |
+
{{ render_python_repr(child) }}{%- if not loop.last -%}, {% endif -%}
|
| 143 |
+
{%- endfor -%}
|
| 144 |
+
{{- "]" -}}
|
| 145 |
+
{%- else -%}
|
| 146 |
+
{{- value -}}
|
| 147 |
+
{%- endif -%}
|
| 148 |
+
{%- endmacro -%}
|
| 149 |
+
|
| 150 |
+
{%- macro render_xml_value(value) -%}
|
| 151 |
+
{%- if value is string -%}{{ render_xml_text(value) }}{%- else -%}{{ render_python_repr(value) }}{%- endif -%}
|
| 152 |
+
{%- endmacro -%}
|
| 153 |
+
|
| 154 |
+
{%- macro render_xml_enum_value(value) -%}
|
| 155 |
+
{%- if value is string -%}"{{- value | replace("\\", "\\\\") | replace("\"", "\\\"") -}}"{%- else -%}"{{- render_python_repr(value) | replace("\\", "\\\\") | replace("\"", "\\\"") -}}"{%- endif -%}
|
| 156 |
+
{%- endmacro -%}
|
| 157 |
+
|
| 158 |
+
{%- macro render_xml_enum(values) -%}
|
| 159 |
+
{%- for value in values -%}{{ render_xml_enum_value(value) }}{%- if not loop.last -%}|{%- endif -%}{%- endfor -%}
|
| 160 |
+
{%- endmacro -%}
|
| 161 |
+
|
| 162 |
+
{%- macro render_xml_default_attr(value) -%}
|
| 163 |
+
{{- " default=" }}{%- if value is string -%}"{{- value | replace("\\", "\\\\") | replace("\"", "\\\"") -}}"{%- else -%}{{ render_xml_value(value) }}{%- endif -%}
|
| 164 |
+
{%- endmacro -%}
|
| 165 |
+
|
| 166 |
+
{%- macro render_xml_attr(name, value) -%}
|
| 167 |
+
{{- " " + name + "=" }}{%- if value == "" -%}""{%- else -%}{{ render_xml_value(value) }}{%- endif -%}
|
| 168 |
+
{%- endmacro -%}
|
| 169 |
+
|
| 170 |
+
{%- macro validate_schema(spec, path, lenient=false, classify=true, in_variant=false) -%}
|
| 171 |
+
{%- if spec is mapping -%}
|
| 172 |
+
{%- if not lenient -%}
|
| 173 |
+
{%- if spec.required is defined -%}
|
| 174 |
+
{%- if spec.required is string or spec.required is not sequence -%}
|
| 175 |
+
{{- raise_exception("Schema '" + path + "' has 'required' but it is not a list.") -}}
|
| 176 |
+
{%- endif -%}
|
| 177 |
+
{%- if spec.required | length > 0 and not spec.properties and not in_variant -%}
|
| 178 |
+
{{- raise_exception("Schema '" + path + "' has required fields but no properties object to define them.") -}}
|
| 179 |
+
{%- endif -%}
|
| 180 |
+
{%- if spec.properties -%}
|
| 181 |
+
{%- for required_name in spec.required -%}
|
| 182 |
+
{%- if required_name not in spec.properties -%}
|
| 183 |
+
{{- raise_exception("Schema '" + path + "' marks '" + required_name + "' as required, but that property is not defined in properties.") -}}
|
| 184 |
+
{%- endif -%}
|
| 185 |
+
{%- endfor -%}
|
| 186 |
+
{%- endif -%}
|
| 187 |
+
{%- endif -%}
|
| 188 |
+
{%- endif -%}
|
| 189 |
+
{#- renderability classification, piggybacking on this walk (no raises here): -#}
|
| 190 |
+
{#- constructs the pretty renderer does not fully handle flip RB.ok so the -#}
|
| 191 |
+
{#- tool falls back to verbatim JSON. Skipped entirely for json presentation. -#}
|
| 192 |
+
{%- if classify -%}
|
| 193 |
+
{%- for key, value in spec | items -%}
|
| 194 |
+
{%- if key == '$ref' -%}
|
| 195 |
+
{%- if value is not string -%}{%- set RB.ok = false -%}
|
| 196 |
+
{%- elif not (value.startswith('#/$defs/') or value.startswith('#/definitions/')) -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 197 |
+
{%- elif key == '$defs' or key == 'definitions' -%}
|
| 198 |
+
{%- if value is mapping -%}
|
| 199 |
+
{%- for dk, dv in value | items -%}
|
| 200 |
+
{{- validate_schema(dv, path + ".$defs." + dk, true) -}}
|
| 201 |
+
{%- endfor -%}
|
| 202 |
+
{%- else -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 203 |
+
{%- elif key == 'type' -%}
|
| 204 |
+
{%- if value is mapping -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 205 |
+
{%- elif key == 'enum' -%}
|
| 206 |
+
{%- if value is string or value is mapping or value is not sequence -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 207 |
+
{%- elif key == 'items' -%}
|
| 208 |
+
{#- any items shape renders: mapping structurally, others via repr detail -#}
|
| 209 |
+
{%- elif key == 'oneOf' or key == 'anyOf' -%}
|
| 210 |
+
{%- if value is mapping or value is string or value is not sequence -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 211 |
+
{%- elif key == 'required' -%}
|
| 212 |
+
{%- if value and not spec.properties -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 213 |
+
{%- elif ('|' ~ key ~ '|') in '|description|default|title|examples|properties|patternProperties|additionalProperties|returns|' -%}
|
| 214 |
+
{%- elif value is mapping -%}
|
| 215 |
+
{%- for uk, uv in value | items -%}
|
| 216 |
+
{%- if value_contains_mapping(uv) == 'true' -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 217 |
+
{%- endfor -%}
|
| 218 |
+
{%- elif value is sequence and value is not string -%}
|
| 219 |
+
{%- if value_contains_mapping(value) == 'true' -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 220 |
+
{%- endif -%}
|
| 221 |
+
{%- endfor -%}
|
| 222 |
+
{%- endif -%}
|
| 223 |
+
{%- if spec.properties -%}
|
| 224 |
+
{%- for child_name, child_spec in spec.properties | items -%}
|
| 225 |
+
{{- validate_schema(child_spec, path + "." + child_name, lenient, classify) -}}
|
| 226 |
+
{%- endfor -%}
|
| 227 |
+
{%- endif -%}
|
| 228 |
+
{%- if 'items' in spec -%}{{- validate_schema(spec['items'], path + "[]", lenient, classify) -}}{%- endif -%}
|
| 229 |
+
{%- if spec.oneOf -%}
|
| 230 |
+
{%- for variant in spec.oneOf -%}{{- validate_schema(variant, path + ".oneOf[" + (loop.index0 | string) + "]", lenient, classify, true) -}}{%- endfor -%}
|
| 231 |
+
{%- endif -%}
|
| 232 |
+
{%- if spec.anyOf -%}
|
| 233 |
+
{%- for variant in spec.anyOf -%}{{- validate_schema(variant, path + ".anyOf[" + (loop.index0 | string) + "]", lenient, classify, true) -}}{%- endfor -%}
|
| 234 |
+
{%- endif -%}
|
| 235 |
+
{%- if spec.additionalProperties is mapping -%}{{- validate_schema(spec.additionalProperties, path + ".additionalProperties", lenient, classify) -}}{%- endif -%}
|
| 236 |
+
{%- if spec.patternProperties is mapping -%}
|
| 237 |
+
{%- for pattern, pattern_spec in spec.patternProperties | items -%}
|
| 238 |
+
{{- validate_schema(pattern_spec, path + ".patternProperties[" + pattern + "]", lenient, classify) -}}
|
| 239 |
+
{%- endfor -%}
|
| 240 |
+
{%- endif -%}
|
| 241 |
+
{%- if spec.returns is mapping -%}{{- validate_schema(spec.returns, path + ".returns", lenient, classify) -}}{%- endif -%}
|
| 242 |
+
{%- endif -%}
|
| 243 |
+
{%- endmacro -%}
|
| 244 |
+
|
| 245 |
+
{%- macro validate_tools(tools_list, classify=true) -%}
|
| 246 |
+
{%- set RB.bad = '|' -%}
|
| 247 |
+
{%- for tool in tools_list -%}
|
| 248 |
+
{%- set fn = tool.function if tool.function is defined else tool -%}
|
| 249 |
+
{%- set RB.ok = true -%}
|
| 250 |
+
{%- if fn.parameters is defined and fn.parameters is string -%}
|
| 251 |
+
{{- raise_exception("tool.function.parameters must be a dict, not a JSON string. Parse it before passing to the template.") -}}
|
| 252 |
+
{%- endif -%}
|
| 253 |
+
{%- if fn.parameters is not defined or fn.parameters is none -%}
|
| 254 |
+
{%- if fn.arguments is defined -%}
|
| 255 |
+
{{- raise_exception("Tool '" + fn.name + "' has 'arguments' instead of 'parameters'. Rename 'arguments' to 'parameters'.") -}}
|
| 256 |
+
{%- else -%}
|
| 257 |
+
{{- raise_exception("Tool '" + fn.name + "' is missing required 'parameters' field. Each tool must have a 'parameters' dict with 'type', 'properties', and 'required' keys.") -}}
|
| 258 |
+
{%- endif -%}
|
| 259 |
+
{%- endif -%}
|
| 260 |
+
{{- validate_schema(fn.parameters, "tool." + fn.name + ".parameters", false, classify) -}}
|
| 261 |
+
{%- if classify -%}
|
| 262 |
+
{%- if fn.parameters is mapping -%}
|
| 263 |
+
{#- unknown container-valued keys at the parameters ROOT are never rendered -#}
|
| 264 |
+
{#- by the pretty path (root extras are dropped) -> verbatim fallback. -#}
|
| 265 |
+
{%- for rk, rv in fn.parameters | items -%}
|
| 266 |
+
{%- if rk not in ['type', 'description', 'enum', 'default', 'properties', 'required', 'optional', 'title', 'items', 'oneOf', 'anyOf', 'additionalProperties', 'patternProperties', 'returns', 'examples', '$defs', 'definitions', '$ref'] -%}
|
| 267 |
+
{%- if rv is mapping or (rv is sequence and rv is not string) -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 268 |
+
{%- endif -%}
|
| 269 |
+
{%- endfor -%}
|
| 270 |
+
{%- else -%}
|
| 271 |
+
{%- set RB.ok = false -%}
|
| 272 |
+
{%- endif -%}
|
| 273 |
+
{%- endif -%}
|
| 274 |
+
{%- if fn.returns is mapping -%}{{- validate_schema(fn.returns, "tool." + fn.name + ".returns", false, classify) -}}{%- endif -%}
|
| 275 |
+
{%- if classify and fn.returns is not defined and fn.response is mapping -%}{{- validate_schema(fn.response, "tool." + fn.name + ".response", true) -}}{%- endif -%}
|
| 276 |
+
{#- unknown container-valued keys at the FUNCTION level are never rendered -> fallback. -#}
|
| 277 |
+
{%- if classify -%}
|
| 278 |
+
{%- for fk, fv in fn | items -%}
|
| 279 |
+
{%- if fk not in ['name', 'description', 'parameters', 'returns', 'response', 'type', 'function'] -%}
|
| 280 |
+
{%- if fv is mapping or (fv is sequence and fv is not string) -%}{%- set RB.ok = false -%}{%- endif -%}
|
| 281 |
+
{%- endif -%}
|
| 282 |
+
{%- endfor -%}
|
| 283 |
+
{%- endif -%}
|
| 284 |
+
{%- if not RB.ok -%}{%- set RB.bad = RB.bad ~ loop.index0 ~ '|' -%}{%- endif -%}
|
| 285 |
+
{%- endfor -%}
|
| 286 |
+
{%- endmacro -%}
|
| 287 |
+
|
| 288 |
+
{%- macro render_tools_json(tools_list) -%}
|
| 289 |
+
{{- "<ifm|tools>" }}
|
| 290 |
+
{%- for tool in tools_list %}
|
| 291 |
+
{{- "\n" }}
|
| 292 |
+
{{- tool | tojson }}
|
| 293 |
+
{%- endfor %}
|
| 294 |
+
{{- "\n</ifm|tools>" }}
|
| 295 |
+
{%- endmacro -%}
|
| 296 |
+
|
| 297 |
+
{%- macro render_xml_schema_attrs(spec, include_value_attrs) -%}
|
| 298 |
+
{%- if spec is mapping -%}
|
| 299 |
+
{%- set structural_keys = ["type", "description", "enum", "default", "properties", "required", "items", "oneOf", "anyOf", "additionalProperties", "patternProperties", "returns"] -%}
|
| 300 |
+
{%- if include_value_attrs and spec.enum -%}{{- " enum=" }}{{ render_xml_enum(spec.enum) }}{%- endif -%}
|
| 301 |
+
{%- if include_value_attrs and spec.default is defined -%}{{ render_xml_default_attr(spec.default) }}{%- endif -%}
|
| 302 |
+
{%- if spec.additionalProperties is defined and spec.additionalProperties is not mapping -%}{{ render_xml_attr("additionalProperties", spec.additionalProperties) }}{%- endif -%}
|
| 303 |
+
{%- if spec.patternProperties is defined and spec.patternProperties is not mapping -%}{{ render_xml_attr("patternProperties", spec.patternProperties) }}{%- endif -%}
|
| 304 |
+
{%- for key, value in spec | items -%}
|
| 305 |
+
{%- if key not in structural_keys -%}
|
| 306 |
+
{{ render_xml_attr(key, value) }}
|
| 307 |
+
{%- endif -%}
|
| 308 |
+
{%- endfor -%}
|
| 309 |
+
{%- endif -%}
|
| 310 |
+
{%- endmacro -%}
|
| 311 |
+
|
| 312 |
+
{%- macro xml_schema_has_children(spec, include_properties, include_description) -%}
|
| 313 |
+
{%- if spec is not mapping -%}
|
| 314 |
+
false
|
| 315 |
+
{%- elif (include_description and spec.description is defined) or (include_properties and spec.properties) or 'items' in spec or spec.oneOf or spec.anyOf or spec.additionalProperties is mapping or spec.patternProperties is mapping or spec.returns is defined -%}
|
| 316 |
+
true
|
| 317 |
+
{%- else -%}
|
| 318 |
+
false
|
| 319 |
+
{%- endif -%}
|
| 320 |
+
{%- endmacro -%}
|
| 321 |
+
|
| 322 |
+
{%- macro render_xml_schema_node(tag, spec, include_properties) -%}
|
| 323 |
+
{%- if spec is mapping and spec['$ref'] is string -%}
|
| 324 |
+
{%- set _r = spec['$ref'] -%}
|
| 325 |
+
{%- set _k = _r[8:] if _r.startswith('#/$defs/') else (_r[14:] if _r.startswith('#/definitions/') else none) -%}
|
| 326 |
+
{%- if _k is not none and ('|' + _k + '|') not in REFS.seen and REFS.defs[_k] is mapping -%}
|
| 327 |
+
{%- set spec = dict((REFS.defs[_k] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 328 |
+
{%- set REFS.seen = REFS.seen + _k + '|' -%}
|
| 329 |
+
{%- if spec['$ref'] is string -%}
|
| 330 |
+
{%- set _r2 = spec['$ref'] -%}
|
| 331 |
+
{%- set _k2 = _r2[8:] if _r2.startswith('#/$defs/') else (_r2[14:] if _r2.startswith('#/definitions/') else none) -%}
|
| 332 |
+
{%- if _k2 is not none and REFS.defs[_k2] is mapping -%}
|
| 333 |
+
{%- set spec = dict((REFS.defs[_k2] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 334 |
+
{%- set REFS.seen = REFS.seen + _k2 + '|' -%}
|
| 335 |
+
{%- endif -%}
|
| 336 |
+
{%- endif -%}
|
| 337 |
+
{%- endif -%}
|
| 338 |
+
{%- endif -%}
|
| 339 |
+
{%- if spec is mapping -%}
|
| 340 |
+
{{- "<" + tag + " type=" + render_compact_type(spec) }}{{ render_xml_schema_attrs(spec, true) }}
|
| 341 |
+
{%- if xml_schema_has_children(spec, include_properties, true) == 'true' -%}
|
| 342 |
+
{{- ">" }}{{ render_xml_schema_children(spec, include_properties, true) }}{{- "</" + tag + ">" }}
|
| 343 |
+
{%- else -%}
|
| 344 |
+
{{- "/>" }}
|
| 345 |
+
{%- endif -%}
|
| 346 |
+
{%- else -%}
|
| 347 |
+
{{- "<" + tag + ">" }}{{ render_xml_value(spec) }}{{- "</" + tag + ">" }}
|
| 348 |
+
{%- endif -%}
|
| 349 |
+
{%- endmacro -%}
|
| 350 |
+
|
| 351 |
+
{%- macro render_xml_pattern_property(pattern, spec) -%}
|
| 352 |
+
{%- if spec is mapping and spec['$ref'] is string -%}
|
| 353 |
+
{%- set _r = spec['$ref'] -%}
|
| 354 |
+
{%- set _k = _r[8:] if _r.startswith('#/$defs/') else (_r[14:] if _r.startswith('#/definitions/') else none) -%}
|
| 355 |
+
{%- if _k is not none and ('|' + _k + '|') not in REFS.seen and REFS.defs[_k] is mapping -%}
|
| 356 |
+
{%- set spec = dict((REFS.defs[_k] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 357 |
+
{%- set REFS.seen = REFS.seen + _k + '|' -%}
|
| 358 |
+
{%- if spec['$ref'] is string -%}
|
| 359 |
+
{%- set _r2 = spec['$ref'] -%}
|
| 360 |
+
{%- set _k2 = _r2[8:] if _r2.startswith('#/$defs/') else (_r2[14:] if _r2.startswith('#/definitions/') else none) -%}
|
| 361 |
+
{%- if _k2 is not none and REFS.defs[_k2] is mapping -%}
|
| 362 |
+
{%- set spec = dict((REFS.defs[_k2] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 363 |
+
{%- set REFS.seen = REFS.seen + _k2 + '|' -%}
|
| 364 |
+
{%- endif -%}
|
| 365 |
+
{%- endif -%}
|
| 366 |
+
{%- endif -%}
|
| 367 |
+
{%- endif -%}
|
| 368 |
+
{%- if spec is mapping -%}
|
| 369 |
+
{{- "<patternProperty" }}{{ render_xml_attr("pattern", pattern) }}{{- " type=" + render_compact_type(spec) }}{{ render_xml_schema_attrs(spec, true) }}
|
| 370 |
+
{%- if xml_schema_has_children(spec, true, true) == 'true' -%}
|
| 371 |
+
{{- ">" }}{{ render_xml_schema_children(spec, true, true) }}{{- "</patternProperty>" }}
|
| 372 |
+
{%- else -%}
|
| 373 |
+
{{- "/>" }}
|
| 374 |
+
{%- endif -%}
|
| 375 |
+
{%- else -%}
|
| 376 |
+
{{- "<patternProperty" }}{{ render_xml_attr("pattern", pattern) }}{{- ">" }}{{ render_xml_value(spec) }}{{- "</patternProperty>" }}
|
| 377 |
+
{%- endif -%}
|
| 378 |
+
{%- endmacro -%}
|
| 379 |
+
|
| 380 |
+
{%- macro render_xml_schema_children(spec, include_properties, include_description) -%}
|
| 381 |
+
{%- if include_description and spec.description is defined -%}{{- "<description>" }}{{ spec.description }}{{- "</description>" }}{%- endif -%}
|
| 382 |
+
{%- if include_properties and spec.properties -%}
|
| 383 |
+
{%- for child_name, child_spec in spec.properties | items -%}
|
| 384 |
+
{{- render_xml_param(child_name, child_spec, spec.required or []) }}
|
| 385 |
+
{%- endfor -%}
|
| 386 |
+
{%- endif -%}
|
| 387 |
+
{%- if 'items' in spec -%}{{ render_xml_schema_node("items", spec['items'], true) }}{%- endif -%}
|
| 388 |
+
{%- if spec.oneOf -%}
|
| 389 |
+
{{- "<oneOf>" }}
|
| 390 |
+
{%- for variant in spec.oneOf -%}{{ render_xml_schema_node("variant", variant, true) }}{%- endfor -%}
|
| 391 |
+
{{- "</oneOf>" }}
|
| 392 |
+
{%- endif -%}
|
| 393 |
+
{%- if spec.anyOf -%}
|
| 394 |
+
{{- "<anyOf>" }}
|
| 395 |
+
{%- for variant in spec.anyOf -%}{{ render_xml_schema_node("variant", variant, true) }}{%- endfor -%}
|
| 396 |
+
{{- "</anyOf>" }}
|
| 397 |
+
{%- endif -%}
|
| 398 |
+
{%- if spec.additionalProperties is mapping -%}{{ render_xml_schema_node("additionalProperties", spec.additionalProperties, true) }}{%- endif -%}
|
| 399 |
+
{%- if spec.patternProperties is mapping -%}
|
| 400 |
+
{{- "<patternProperties>" }}
|
| 401 |
+
{%- for pattern, pattern_spec in spec.patternProperties | items -%}{{ render_xml_pattern_property(pattern, pattern_spec) }}{%- endfor -%}
|
| 402 |
+
{{- "</patternProperties>" }}
|
| 403 |
+
{%- elif spec.patternProperties is defined -%}<patternProperties>{{ render_xml_value(spec.patternProperties) }}</patternProperties>{%- endif -%}
|
| 404 |
+
{%- if spec.returns is mapping -%}{{ render_xml_schema_node("returns", spec.returns, true) }}{%- elif spec.returns is defined -%}<returns>{{ render_xml_value(spec.returns) }}</returns>{%- endif -%}
|
| 405 |
+
{%- endmacro -%}
|
| 406 |
+
|
| 407 |
+
{%- macro render_xml_param(name, spec, required_list) -%}
|
| 408 |
+
{%- if spec is mapping and spec['$ref'] is string -%}
|
| 409 |
+
{%- set _r = spec['$ref'] -%}
|
| 410 |
+
{%- set _k = _r[8:] if _r.startswith('#/$defs/') else (_r[14:] if _r.startswith('#/definitions/') else none) -%}
|
| 411 |
+
{%- if _k is not none and ('|' + _k + '|') not in REFS.seen and REFS.defs[_k] is mapping -%}
|
| 412 |
+
{%- set spec = dict((REFS.defs[_k] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 413 |
+
{%- set REFS.seen = REFS.seen + _k + '|' -%}
|
| 414 |
+
{%- if spec['$ref'] is string -%}
|
| 415 |
+
{%- set _r2 = spec['$ref'] -%}
|
| 416 |
+
{%- set _k2 = _r2[8:] if _r2.startswith('#/$defs/') else (_r2[14:] if _r2.startswith('#/definitions/') else none) -%}
|
| 417 |
+
{%- if _k2 is not none and REFS.defs[_k2] is mapping -%}
|
| 418 |
+
{%- set spec = dict((REFS.defs[_k2] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 419 |
+
{%- set REFS.seen = REFS.seen + _k2 + '|' -%}
|
| 420 |
+
{%- endif -%}
|
| 421 |
+
{%- endif -%}
|
| 422 |
+
{%- endif -%}
|
| 423 |
+
{%- endif -%}
|
| 424 |
+
{{- "<param name=" + name + " type=" + render_compact_type(spec) }}
|
| 425 |
+
{%- if name in (required_list or []) -%}{{- " required=true" }}{%- endif -%}
|
| 426 |
+
{%- if spec.enum -%}{{- " enum=" }}{{ render_xml_enum(spec.enum) }}{%- endif -%}
|
| 427 |
+
{%- if spec.default is defined -%}{{ render_xml_default_attr(spec.default) }}{%- endif -%}
|
| 428 |
+
{{- render_xml_schema_attrs(spec, false) }}
|
| 429 |
+
{%- if spec.description or xml_schema_has_children(spec, true, false) == 'true' -%}
|
| 430 |
+
{{- ">" }}
|
| 431 |
+
{%- if spec.description -%}{{ spec.description }}{%- endif -%}
|
| 432 |
+
{{- render_xml_schema_children(spec, true, false) }}
|
| 433 |
+
{{- "</param>" }}
|
| 434 |
+
{%- else -%}
|
| 435 |
+
{{- "/>" }}
|
| 436 |
+
{%- endif -%}
|
| 437 |
+
{%- endmacro -%}
|
| 438 |
+
|
| 439 |
+
{%- macro render_tools_xml(tools_list) -%}
|
| 440 |
+
{{- "<ifm|tools>" }}
|
| 441 |
+
{%- for tool in tools_list -%}
|
| 442 |
+
{%- set fn = tool.function if tool.function is defined else tool -%}
|
| 443 |
+
{%- set REFS.defs = fn.parameters['$defs'] if (fn.parameters is mapping and fn.parameters['$defs'] is mapping) else (fn.parameters['definitions'] if (fn.parameters is mapping and fn.parameters['definitions'] is mapping) else {}) -%}
|
| 444 |
+
{%- set REFS.seen = '|' -%}
|
| 445 |
+
{%- set fnp = namespace(p=fn.parameters) -%}
|
| 446 |
+
{%- if fnp.p is mapping and fnp.p['$ref'] is string -%}
|
| 447 |
+
{%- set _r = fnp.p['$ref'] -%}
|
| 448 |
+
{%- set _k = _r[8:] if _r.startswith('#/$defs/') else (_r[14:] if _r.startswith('#/definitions/') else none) -%}
|
| 449 |
+
{%- if _k is not none and REFS.defs[_k] is mapping -%}
|
| 450 |
+
{%- set fnp.p = dict((REFS.defs[_k] | items | list) + (fnp.p | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 451 |
+
{%- set REFS.seen = REFS.seen + _k + '|' -%}
|
| 452 |
+
{%- endif -%}
|
| 453 |
+
{%- endif -%}
|
| 454 |
+
{{- "\n<function name=" + fn.name + ">" }}
|
| 455 |
+
{%- if fn.description -%}
|
| 456 |
+
{{- "<description>" }}{{ fn.description }}{{- "</description>" }}
|
| 457 |
+
{%- endif -%}
|
| 458 |
+
{{- "<parameters>" }}
|
| 459 |
+
{%- if fnp.p and fnp.p.properties -%}
|
| 460 |
+
{%- for pname, pspec in fnp.p.properties | items -%}
|
| 461 |
+
{{- render_xml_param(pname, pspec, fnp.p.required or []) }}
|
| 462 |
+
{%- endfor -%}
|
| 463 |
+
{%- elif fnp.p is mapping and (fnp.p.oneOf or fnp.p.anyOf or 'items' in fnp.p) -%}
|
| 464 |
+
{{- render_xml_schema_children(fnp.p, true, false) }}
|
| 465 |
+
{%- endif -%}
|
| 466 |
+
{{- "</parameters>" }}
|
| 467 |
+
{%- set fn_ret = fn.returns if fn.returns is defined else fn.response -%}
|
| 468 |
+
{%- if fn_ret is mapping -%}{{ render_xml_schema_node("returns", fn_ret, true) }}{%- elif fn_ret is defined -%}<returns>{{ render_xml_value(fn_ret) }}</returns>{%- endif -%}
|
| 469 |
+
{{- "</function>" }}
|
| 470 |
+
{%- endfor -%}
|
| 471 |
+
{{- "\n</ifm|tools>" }}
|
| 472 |
+
{%- endmacro -%}
|
| 473 |
+
|
| 474 |
+
{%- macro render_markdown_literal(value) -%}
|
| 475 |
+
{%- if value is string and value == "" -%}""
|
| 476 |
+
{%- elif value is string -%}`{{ value | replace("\n", "\\n") }}`
|
| 477 |
+
{%- else -%}`{{ render_python_repr(value) }}`
|
| 478 |
+
{%- endif -%}
|
| 479 |
+
{%- endmacro -%}
|
| 480 |
+
|
| 481 |
+
{%- macro render_allowed_values(values) -%}
|
| 482 |
+
{%- for value in values -%}{{ render_markdown_literal(value) }}{% if not loop.last %}, {% endif %}{%- endfor -%}
|
| 483 |
+
{%- endmacro -%}
|
| 484 |
+
|
| 485 |
+
{%- macro render_markdown_value(value) -%}
|
| 486 |
+
{%- if value is string and value == "" -%}""{%- elif value is string -%}{{ value }}{%- else -%}{{ render_python_repr(value) }}{%- endif -%}
|
| 487 |
+
{%- endmacro -%}
|
| 488 |
+
|
| 489 |
+
{%- macro render_markdown_detail(indent, label, value) -%}
|
| 490 |
+
{{- "\n" + indent + " - " + label + ": " }}{{ render_markdown_value(value) }}
|
| 491 |
+
{%- endmacro -%}
|
| 492 |
+
|
| 493 |
+
{%- macro render_markdown_metadata_detail(label, value) -%}
|
| 494 |
+
{{- "\n- " + label + ": " }}{{ render_markdown_value(value) }}
|
| 495 |
+
{%- endmacro -%}
|
| 496 |
+
|
| 497 |
+
{%- macro render_markdown_schema_annotations(spec, indent, include_value_details) -%}
|
| 498 |
+
{%- if include_value_details and spec.description is defined -%}{{ render_markdown_detail(indent, "Description", spec.description | replace("\n", "\n" + indent + " ")) }}{%- endif -%}
|
| 499 |
+
{%- if include_value_details and spec.enum is defined -%}{{- "\n" + indent + " - Allowed values: " }}{{ render_allowed_values(spec.enum) }}{%- endif -%}
|
| 500 |
+
{%- if include_value_details and spec.default is defined -%}{{- "\n" + indent + " - Default: " }}{{ render_markdown_literal(spec.default) }}{%- endif -%}
|
| 501 |
+
{%- if spec.additionalProperties is defined -%}
|
| 502 |
+
{%- if spec.additionalProperties is mapping -%}
|
| 503 |
+
{{- "\n" + indent + " - Additional properties *(" + render_markdown_type(spec.additionalProperties) + ")*" }}
|
| 504 |
+
{{- render_markdown_schema_details(spec.additionalProperties, indent + " ", true) }}
|
| 505 |
+
{%- else -%}
|
| 506 |
+
{{ render_markdown_detail(indent, "Additional properties", spec.additionalProperties) }}
|
| 507 |
+
{%- endif -%}
|
| 508 |
+
{%- endif -%}
|
| 509 |
+
{%- endmacro -%}
|
| 510 |
+
|
| 511 |
+
{%- macro render_markdown_metadata_annotations(spec) -%}
|
| 512 |
+
{%- if spec.description is defined -%}{{ render_markdown_metadata_detail("Description", spec.description | replace("\n", "\n ")) }}{%- endif -%}
|
| 513 |
+
{%- if spec.enum is defined -%}{{- "\n- Allowed values: " }}{{ render_allowed_values(spec.enum) }}{%- endif -%}
|
| 514 |
+
{%- if spec.default is defined -%}{{- "\n- Default: " }}{{ render_markdown_literal(spec.default) }}{%- endif -%}
|
| 515 |
+
{%- if spec.additionalProperties is defined -%}
|
| 516 |
+
{%- if spec.additionalProperties is mapping -%}
|
| 517 |
+
{{- "\n- Additional properties *(" + render_markdown_type(spec.additionalProperties) + ")*" }}
|
| 518 |
+
{{- render_markdown_schema_details(spec.additionalProperties, "", true) }}
|
| 519 |
+
{%- else -%}
|
| 520 |
+
{{ render_markdown_metadata_detail("Additional properties", spec.additionalProperties) }}
|
| 521 |
+
{%- endif -%}
|
| 522 |
+
{%- endif -%}
|
| 523 |
+
{%- endmacro -%}
|
| 524 |
+
|
| 525 |
+
{%- macro render_markdown_schema_extras(spec, indent) -%}
|
| 526 |
+
{%- set rendered_keys = ["type", "description", "enum", "default", "properties", "required", "items", "oneOf", "anyOf", "additionalProperties", "patternProperties", "returns"] -%}
|
| 527 |
+
{%- for key, value in spec | items -%}
|
| 528 |
+
{%- if key not in rendered_keys -%}
|
| 529 |
+
{{- "\n" + indent + " - " + key + ": " }}{{ render_markdown_value(value) }}
|
| 530 |
+
{%- endif -%}
|
| 531 |
+
{%- endfor -%}
|
| 532 |
+
{%- endmacro -%}
|
| 533 |
+
|
| 534 |
+
{%- macro render_markdown_metadata_extras(spec) -%}
|
| 535 |
+
{%- set rendered_keys = ["type", "description", "enum", "default", "properties", "required", "items", "oneOf", "anyOf", "additionalProperties", "patternProperties", "returns"] -%}
|
| 536 |
+
{%- for key, value in spec | items -%}
|
| 537 |
+
{%- if key not in rendered_keys -%}
|
| 538 |
+
{{- "\n- " + key + ": " }}{{ render_markdown_value(value) }}
|
| 539 |
+
{%- endif -%}
|
| 540 |
+
{%- endfor -%}
|
| 541 |
+
{%- endmacro -%}
|
| 542 |
+
|
| 543 |
+
{%- macro markdown_schema_has_extra(spec) -%}
|
| 544 |
+
{%- set rendered_keys = ["type", "description", "enum", "default", "properties", "required", "items", "oneOf", "anyOf", "additionalProperties", "patternProperties", "returns"] -%}
|
| 545 |
+
{%- set found = namespace(value='false') -%}
|
| 546 |
+
{%- for key, value in spec | items -%}
|
| 547 |
+
{%- if key not in rendered_keys -%}{%- set found.value = 'true' -%}{%- endif -%}
|
| 548 |
+
{%- endfor -%}
|
| 549 |
+
{{- found.value -}}
|
| 550 |
+
{%- endmacro -%}
|
| 551 |
+
|
| 552 |
+
{%- macro markdown_parameter_schema_has_details(spec) -%}
|
| 553 |
+
{%- if spec.description is defined or spec.enum is defined or spec.default is defined or spec.additionalProperties is defined or spec.patternProperties is defined or 'items' in spec or spec.oneOf or spec.anyOf or spec.returns is defined or markdown_schema_has_extra(spec) == 'true' -%}
|
| 554 |
+
true
|
| 555 |
+
{%- else -%}
|
| 556 |
+
false
|
| 557 |
+
{%- endif -%}
|
| 558 |
+
{%- endmacro -%}
|
| 559 |
+
|
| 560 |
+
{%- macro render_markdown_schema_structure(spec, indent, include_properties) -%}
|
| 561 |
+
{%- if include_properties and spec.properties -%}
|
| 562 |
+
{%- for child_name, child_spec in spec.properties | items -%}
|
| 563 |
+
{{- render_markdown_param(child_name, child_spec, spec.required or [], indent + " ") }}
|
| 564 |
+
{%- endfor -%}
|
| 565 |
+
{%- endif -%}
|
| 566 |
+
{%- if 'items' in spec and spec['items'] is mapping -%}
|
| 567 |
+
{{- "\n" + indent + " - Items *(" + render_markdown_type(spec['items']) + ")*" }}
|
| 568 |
+
{{- render_markdown_schema_details(spec['items'], indent + " ", true) }}
|
| 569 |
+
{%- elif 'items' in spec -%}
|
| 570 |
+
{{ render_markdown_detail(indent, "Items", spec['items']) }}
|
| 571 |
+
{%- endif -%}
|
| 572 |
+
{%- if spec.oneOf -%}
|
| 573 |
+
{{- "\n" + indent + " - oneOf:" }}
|
| 574 |
+
{%- for variant in spec.oneOf -%}
|
| 575 |
+
{{- "\n" + indent + " - Variant " }}{{ loop.index }}{{- " *(" + render_markdown_type(variant) + ")*" }}
|
| 576 |
+
{{- render_markdown_schema_details(variant, indent + " ", true) }}
|
| 577 |
+
{%- endfor -%}
|
| 578 |
+
{%- endif -%}
|
| 579 |
+
{%- if spec.anyOf -%}
|
| 580 |
+
{{- "\n" + indent + " - anyOf:" }}
|
| 581 |
+
{%- for variant in spec.anyOf -%}
|
| 582 |
+
{{- "\n" + indent + " - Variant " }}{{ loop.index }}{{- " *(" + render_markdown_type(variant) + ")*" }}
|
| 583 |
+
{{- render_markdown_schema_details(variant, indent + " ", true) }}
|
| 584 |
+
{%- endfor -%}
|
| 585 |
+
{%- endif -%}
|
| 586 |
+
{%- if spec.patternProperties is mapping -%}
|
| 587 |
+
{{- "\n" + indent + " - Pattern properties:" }}
|
| 588 |
+
{%- for pattern, pattern_spec in spec.patternProperties | items -%}
|
| 589 |
+
{%- if pattern_spec is mapping -%}
|
| 590 |
+
{{- "\n" + indent + " - `" + pattern + "` *(" + render_markdown_type(pattern_spec) + ")*" }}
|
| 591 |
+
{{- render_markdown_schema_details(pattern_spec, indent + " ", true) }}
|
| 592 |
+
{%- else -%}
|
| 593 |
+
{{- "\n" + indent + " - `" + pattern + "`: " }}{{ render_markdown_value(pattern_spec) }}
|
| 594 |
+
{%- endif -%}
|
| 595 |
+
{%- endfor -%}
|
| 596 |
+
{%- elif spec.patternProperties is defined -%}
|
| 597 |
+
{{ render_markdown_detail(indent, "Pattern properties", spec.patternProperties) }}
|
| 598 |
+
{%- endif -%}
|
| 599 |
+
{%- if spec.returns is mapping -%}
|
| 600 |
+
{{- "\n" + indent + " - Returns *(" + render_markdown_type(spec.returns) + ")*" }}
|
| 601 |
+
{{- render_markdown_schema_details(spec.returns, indent + " ", true) }}
|
| 602 |
+
{%- elif spec.returns is defined -%}
|
| 603 |
+
{{ render_markdown_detail(indent, "Returns", spec.returns) }}
|
| 604 |
+
{%- endif -%}
|
| 605 |
+
{%- endmacro -%}
|
| 606 |
+
|
| 607 |
+
{%- macro render_markdown_schema_details(spec, indent, include_value_details) -%}
|
| 608 |
+
{%- if spec is mapping and spec['$ref'] is string -%}
|
| 609 |
+
{%- set _r = spec['$ref'] -%}
|
| 610 |
+
{%- set _k = _r[8:] if _r.startswith('#/$defs/') else (_r[14:] if _r.startswith('#/definitions/') else none) -%}
|
| 611 |
+
{%- if _k is not none and ('|' + _k + '|') not in REFS.seen and REFS.defs[_k] is mapping -%}
|
| 612 |
+
{%- set spec = dict((REFS.defs[_k] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 613 |
+
{%- set REFS.seen = REFS.seen + _k + '|' -%}
|
| 614 |
+
{%- if spec['$ref'] is string -%}
|
| 615 |
+
{%- set _r2 = spec['$ref'] -%}
|
| 616 |
+
{%- set _k2 = _r2[8:] if _r2.startswith('#/$defs/') else (_r2[14:] if _r2.startswith('#/definitions/') else none) -%}
|
| 617 |
+
{%- if _k2 is not none and REFS.defs[_k2] is mapping -%}
|
| 618 |
+
{%- set spec = dict((REFS.defs[_k2] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 619 |
+
{%- set REFS.seen = REFS.seen + _k2 + '|' -%}
|
| 620 |
+
{%- endif -%}
|
| 621 |
+
{%- endif -%}
|
| 622 |
+
{%- endif -%}
|
| 623 |
+
{%- endif -%}
|
| 624 |
+
{%- if spec is mapping -%}
|
| 625 |
+
{{- render_markdown_schema_annotations(spec, indent, include_value_details) }}
|
| 626 |
+
{{- render_markdown_schema_structure(spec, indent, true) }}
|
| 627 |
+
{{- render_markdown_schema_extras(spec, indent) }}
|
| 628 |
+
{%- elif spec is not sameas true and spec is not sameas false -%}
|
| 629 |
+
{{- "\n" + indent + " - Value: " }}{{ render_markdown_literal(spec) }}
|
| 630 |
+
{%- endif -%}
|
| 631 |
+
{%- endmacro -%}
|
| 632 |
+
|
| 633 |
+
{%- macro render_markdown_parameter_schema(spec) -%}
|
| 634 |
+
{%- if spec is mapping and spec['$ref'] is string -%}
|
| 635 |
+
{%- set _r = spec['$ref'] -%}
|
| 636 |
+
{%- set _k = _r[8:] if _r.startswith('#/$defs/') else (_r[14:] if _r.startswith('#/definitions/') else none) -%}
|
| 637 |
+
{%- if _k is not none and ('|' + _k + '|') not in REFS.seen and REFS.defs[_k] is mapping -%}
|
| 638 |
+
{%- set spec = dict((REFS.defs[_k] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 639 |
+
{%- set REFS.seen = REFS.seen + _k + '|' -%}
|
| 640 |
+
{%- if spec['$ref'] is string -%}
|
| 641 |
+
{%- set _r2 = spec['$ref'] -%}
|
| 642 |
+
{%- set _k2 = _r2[8:] if _r2.startswith('#/$defs/') else (_r2[14:] if _r2.startswith('#/definitions/') else none) -%}
|
| 643 |
+
{%- if _k2 is not none and REFS.defs[_k2] is mapping -%}
|
| 644 |
+
{%- set spec = dict((REFS.defs[_k2] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 645 |
+
{%- set REFS.seen = REFS.seen + _k2 + '|' -%}
|
| 646 |
+
{%- endif -%}
|
| 647 |
+
{%- endif -%}
|
| 648 |
+
{%- endif -%}
|
| 649 |
+
{%- endif -%}
|
| 650 |
+
{%- if spec is mapping -%}
|
| 651 |
+
{{- render_markdown_metadata_annotations(spec) }}
|
| 652 |
+
{%- if 'items' in spec and spec['items'] is mapping -%}
|
| 653 |
+
{{- "\n- Items *(" + render_markdown_type(spec['items']) + ")*" }}
|
| 654 |
+
{{- render_markdown_schema_details(spec['items'], "", true) }}
|
| 655 |
+
{%- elif 'items' in spec -%}
|
| 656 |
+
{{ render_markdown_metadata_detail("Items", spec['items']) }}
|
| 657 |
+
{%- endif -%}
|
| 658 |
+
{%- if spec.oneOf -%}
|
| 659 |
+
{{- "\n- oneOf:" }}
|
| 660 |
+
{%- for variant in spec.oneOf -%}
|
| 661 |
+
{{- "\n - Variant " }}{{ loop.index }}{{- " *(" + render_markdown_type(variant) + ")*" }}
|
| 662 |
+
{{- render_markdown_schema_details(variant, " ", true) }}
|
| 663 |
+
{%- endfor -%}
|
| 664 |
+
{%- endif -%}
|
| 665 |
+
{%- if spec.anyOf -%}
|
| 666 |
+
{{- "\n- anyOf:" }}
|
| 667 |
+
{%- for variant in spec.anyOf -%}
|
| 668 |
+
{{- "\n - Variant " }}{{ loop.index }}{{- " *(" + render_markdown_type(variant) + ")*" }}
|
| 669 |
+
{{- render_markdown_schema_details(variant, " ", true) }}
|
| 670 |
+
{%- endfor -%}
|
| 671 |
+
{%- endif -%}
|
| 672 |
+
{%- if spec.patternProperties is mapping -%}
|
| 673 |
+
{{- "\n- Pattern properties:" }}
|
| 674 |
+
{%- for pattern, pattern_spec in spec.patternProperties | items -%}
|
| 675 |
+
{%- if pattern_spec is mapping -%}
|
| 676 |
+
{{- "\n - `" + pattern + "` *(" + render_markdown_type(pattern_spec) + ")*" }}
|
| 677 |
+
{{- render_markdown_schema_details(pattern_spec, " ", true) }}
|
| 678 |
+
{%- else -%}
|
| 679 |
+
{{- "\n - `" + pattern + "`: " }}{{ render_markdown_value(pattern_spec) }}
|
| 680 |
+
{%- endif -%}
|
| 681 |
+
{%- endfor -%}
|
| 682 |
+
{%- elif spec.patternProperties is defined -%}
|
| 683 |
+
{{ render_markdown_metadata_detail("Pattern properties", spec.patternProperties) }}
|
| 684 |
+
{%- endif -%}
|
| 685 |
+
{%- if spec.returns is mapping -%}
|
| 686 |
+
{{- "\n- Returns *(" + render_markdown_type(spec.returns) + ")*" }}
|
| 687 |
+
{{- render_markdown_schema_details(spec.returns, "", true) }}
|
| 688 |
+
{%- elif spec.returns is defined -%}
|
| 689 |
+
{{ render_markdown_metadata_detail("Returns", spec.returns) }}
|
| 690 |
+
{%- endif -%}
|
| 691 |
+
{{- render_markdown_metadata_extras(spec) }}
|
| 692 |
+
{%- endif -%}
|
| 693 |
+
{%- endmacro -%}
|
| 694 |
+
|
| 695 |
+
{%- macro render_markdown_param(name, spec, required_list, indent) -%}
|
| 696 |
+
{%- if spec is mapping and spec['$ref'] is string -%}
|
| 697 |
+
{%- set _r = spec['$ref'] -%}
|
| 698 |
+
{%- set _k = _r[8:] if _r.startswith('#/$defs/') else (_r[14:] if _r.startswith('#/definitions/') else none) -%}
|
| 699 |
+
{%- if _k is not none and ('|' + _k + '|') not in REFS.seen and REFS.defs[_k] is mapping -%}
|
| 700 |
+
{%- set spec = dict((REFS.defs[_k] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 701 |
+
{%- set REFS.seen = REFS.seen + _k + '|' -%}
|
| 702 |
+
{%- if spec['$ref'] is string -%}
|
| 703 |
+
{%- set _r2 = spec['$ref'] -%}
|
| 704 |
+
{%- set _k2 = _r2[8:] if _r2.startswith('#/$defs/') else (_r2[14:] if _r2.startswith('#/definitions/') else none) -%}
|
| 705 |
+
{%- if _k2 is not none and REFS.defs[_k2] is mapping -%}
|
| 706 |
+
{%- set spec = dict((REFS.defs[_k2] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 707 |
+
{%- set REFS.seen = REFS.seen + _k2 + '|' -%}
|
| 708 |
+
{%- endif -%}
|
| 709 |
+
{%- endif -%}
|
| 710 |
+
{%- endif -%}
|
| 711 |
+
{%- endif -%}
|
| 712 |
+
{{- "\n" + indent + "- `" + name + "` *(" + render_markdown_type(spec) }}
|
| 713 |
+
{%- if name in (required_list or []) -%}{{- ", required" }}{%- endif -%}
|
| 714 |
+
{{- ")*" }}
|
| 715 |
+
{%- if spec.description -%}{{- " - " + spec.description | replace("\n", "\n" + indent + " ") }}{%- endif -%}
|
| 716 |
+
{%- if spec.enum -%}
|
| 717 |
+
{{- "\n" + indent + " - Allowed values: " }}{{ render_allowed_values(spec.enum) }}
|
| 718 |
+
{%- endif -%}
|
| 719 |
+
{%- if spec.default is defined -%}
|
| 720 |
+
{{- "\n" + indent + " - Default: " }}{{ render_markdown_literal(spec.default) }}
|
| 721 |
+
{%- endif -%}
|
| 722 |
+
{{- render_markdown_schema_details(spec, indent, false) }}
|
| 723 |
+
{%- endmacro -%}
|
| 724 |
+
|
| 725 |
+
{%- macro render_tools_markdown(tools_list) -%}
|
| 726 |
+
{{- "<ifm|tools>" }}
|
| 727 |
+
{%- for tool in tools_list -%}
|
| 728 |
+
{%- set fn = tool.function if tool.function is defined else tool -%}
|
| 729 |
+
{%- set REFS.defs = fn.parameters['$defs'] if (fn.parameters is mapping and fn.parameters['$defs'] is mapping) else (fn.parameters['definitions'] if (fn.parameters is mapping and fn.parameters['definitions'] is mapping) else {}) -%}
|
| 730 |
+
{%- set REFS.seen = '|' -%}
|
| 731 |
+
{%- set fnp = namespace(p=fn.parameters) -%}
|
| 732 |
+
{%- if fnp.p is mapping and fnp.p['$ref'] is string -%}
|
| 733 |
+
{%- set _r = fnp.p['$ref'] -%}
|
| 734 |
+
{%- set _k = _r[8:] if _r.startswith('#/$defs/') else (_r[14:] if _r.startswith('#/definitions/') else none) -%}
|
| 735 |
+
{%- if _k is not none and REFS.defs[_k] is mapping -%}
|
| 736 |
+
{%- set fnp.p = dict((REFS.defs[_k] | items | list) + (fnp.p | items | rejectattr('0', 'equalto', '$ref') | list)) -%}
|
| 737 |
+
{%- set REFS.seen = REFS.seen + _k + '|' -%}
|
| 738 |
+
{%- endif -%}
|
| 739 |
+
{%- endif -%}
|
| 740 |
+
{{- "\n## " + fn.name }}
|
| 741 |
+
{%- if fn.description -%}
|
| 742 |
+
{{- "\n" + fn.description }}
|
| 743 |
+
{%- endif -%}
|
| 744 |
+
{{- "\n\n**Parameters**" }}
|
| 745 |
+
{%- if fnp.p and fnp.p.properties -%}
|
| 746 |
+
{%- for pname, pspec in fnp.p.properties | items -%}
|
| 747 |
+
{{- render_markdown_param(pname, pspec, fnp.p.required or [], "") }}
|
| 748 |
+
{%- endfor -%}
|
| 749 |
+
{%- elif fnp.p is mapping and (fnp.p.oneOf or fnp.p.anyOf or 'items' in fnp.p) -%}
|
| 750 |
+
{{- render_markdown_parameter_schema(fnp.p) }}
|
| 751 |
+
{%- else -%}
|
| 752 |
+
{{- "\n- None" }}
|
| 753 |
+
{%- endif -%}
|
| 754 |
+
{%- set fn_ret = fn.returns if fn.returns is defined else fn.response -%}
|
| 755 |
+
{%- if fn_ret is mapping -%}
|
| 756 |
+
{{- "\n\n**Returns**" }}
|
| 757 |
+
{{- "\n- Return *(" + render_markdown_type(fn_ret) + ")*" }}
|
| 758 |
+
{{- render_markdown_schema_details(fn_ret, "", true) }}
|
| 759 |
+
{%- elif fn_ret is defined -%}
|
| 760 |
+
{{- "\n\n**Returns**\n- " }}{{ render_markdown_value(fn_ret) }}
|
| 761 |
+
{%- endif -%}
|
| 762 |
+
{%- if not loop.last -%}{{- "\n" }}{%- endif -%}
|
| 763 |
+
{%- endfor -%}
|
| 764 |
+
{{- "\n</ifm|tools>" }}
|
| 765 |
+
{%- endmacro -%}
|
| 766 |
+
|
| 767 |
+
{%- macro render_tool_presentation(tools_list, fmt) -%}
|
| 768 |
+
{%- if fmt == 'json' -%}
|
| 769 |
+
{{- render_tools_json(tools_list) }}
|
| 770 |
+
{%- elif RB.bad != '|' -%}
|
| 771 |
+
{#- some tool uses constructs the pretty renderers cannot represent (verdicts -#}
|
| 772 |
+
{#- computed during validate_tools): render the WHOLE toolset exactly as the -#}
|
| 773 |
+
{#- json presentation would, so the block stays uniform and model-familiar. -#}
|
| 774 |
+
{{- render_tools_json(tools_list) }}
|
| 775 |
+
{%- elif fmt == 'xml' -%}
|
| 776 |
+
{{- render_tools_xml(tools_list) }}
|
| 777 |
+
{%- elif fmt == 'markdown' -%}
|
| 778 |
+
{{- render_tools_markdown(tools_list) }}
|
| 779 |
+
{%- else -%}
|
| 780 |
+
{{- raise_exception("Unsupported tool_presentation_format: '" + fmt + "'. Supported formats: json, xml, markdown.") }}
|
| 781 |
+
{%- endif -%}
|
| 782 |
+
{%- endmacro -%}
|
| 783 |
+
|
| 784 |
+
{%- macro render_call_instructions(fmt) -%}
|
| 785 |
+
{%- if fmt == 'json' -%}
|
| 786 |
+
{{- "Wrap all tool calls in a single <ifm|tool_calls></ifm|tool_calls> block. For each call, emit one JSON object with the function name and arguments on the same line inside <ifm|tool_call></ifm|tool_call> tags:\n\n<ifm|tool_calls>\n<ifm|tool_call>{\"name\": <function-name>, \"arguments\": <args-json-object>}</ifm|tool_call>\n</ifm|tool_calls>" }}
|
| 787 |
+
{%- elif fmt == 'xml' -%}
|
| 788 |
+
{{- "Wrap all tool calls in a single <ifm|tool_calls></ifm|tool_calls> block. For each call, write the function name at the start of <ifm|tool_call>, followed by paired <ifm|arg_key> and <ifm|arg_value> tags for each argument:\n\n<ifm|tool_calls>\n<ifm|tool_call>$FUNCTION_NAME\n<ifm|arg_key>$PARAMETER_NAME</ifm|arg_key>\n<ifm|arg_value>$PARAMETER_VALUE</ifm|arg_value>\n...\n</ifm|tool_call>\n</ifm|tool_calls>\n\nString and scalar parameters should be written as plain text. Array and object parameters should be written as JSON literals." }}
|
| 789 |
+
{%- elif fmt == 'xml_typed' -%}
|
| 790 |
+
{{- "Wrap all tool calls in a single <ifm|tool_calls></ifm|tool_calls> block. For each call, write the function name at the start of <ifm|tool_call>, followed by <ifm|arg_key>, <ifm|arg_type>, and <ifm|arg_value> tags for each argument:\n\n<ifm|tool_calls>\n<ifm|tool_call>$FUNCTION_NAME\n<ifm|arg_key>$PARAMETER_NAME</ifm|arg_key>\n<ifm|arg_type>$ARGUMENT_TYPE</ifm|arg_type>\n<ifm|arg_value>$PARAMETER_VALUE</ifm|arg_value>\n...\n</ifm|tool_call>\n</ifm|tool_calls>\n\nUse the parameter type shown in the tool definition. If that type contains anyOf or oneOf, use the actual argument value type instead. String and scalar parameters should be written as plain text. Array and object parameters should be written as JSON literals." }}
|
| 791 |
+
{%- else -%}
|
| 792 |
+
{{- raise_exception("Unsupported tool_call_format: '" + fmt + "'. Supported formats: json, xml, xml_typed.") }}
|
| 793 |
+
{%- endif -%}
|
| 794 |
+
{%- endmacro -%}
|
| 795 |
+
|
| 796 |
+
{%- macro render_system_with_tools(tools_list, system_content, presentation_fmt, call_fmt) -%}
|
| 797 |
+
{{- "<|ifm|im_start|>system\n# Tools\nYou may call one or more tools to assist with the user query.\n\nAvailable tools are:\n\n" }}
|
| 798 |
+
{{- render_tool_presentation(tools_list, presentation_fmt) }}
|
| 799 |
+
{{- "\n\nWhen calling tools, you MUST follow the tool-call format below:\n\n" }}
|
| 800 |
+
{{- render_call_instructions(call_fmt) }}
|
| 801 |
+
{%- if system_content -%}
|
| 802 |
+
{{- "\n\n" + system_content }}
|
| 803 |
+
{%- endif -%}
|
| 804 |
+
{{- "<|ifm|im_end|>" }}
|
| 805 |
+
{%- endmacro -%}
|
| 806 |
+
|
| 807 |
+
{%- macro render_argument_value(value) -%}
|
| 808 |
+
{%- if value is string -%}{{- value -}}{%- else -%}{{- value | tojson -}}{%- endif -%}
|
| 809 |
+
{%- endmacro -%}
|
| 810 |
+
|
| 811 |
+
{%- macro render_value_type(value) -%}
|
| 812 |
+
{%- if value is none -%}null
|
| 813 |
+
{%- elif value is boolean -%}boolean
|
| 814 |
+
{%- elif value is integer -%}integer
|
| 815 |
+
{%- elif value is number -%}number
|
| 816 |
+
{%- elif value is string -%}string
|
| 817 |
+
{%- elif value is mapping -%}object
|
| 818 |
+
{%- elif value is sequence -%}array
|
| 819 |
+
{%- else -%}any
|
| 820 |
+
{%- endif -%}
|
| 821 |
+
{%- endmacro -%}
|
| 822 |
+
|
| 823 |
+
{%- macro schema_has_combinator(spec) -%}
|
| 824 |
+
{%- if spec.oneOf or spec.anyOf -%}
|
| 825 |
+
true
|
| 826 |
+
{%- elif spec.type is defined and spec.type is sequence and spec.type is not string and spec.type | length > 1 -%}
|
| 827 |
+
true
|
| 828 |
+
{%- elif spec.type == "array" and 'items' in spec -%}
|
| 829 |
+
{{- schema_has_combinator(spec['items']) -}}
|
| 830 |
+
{%- elif spec.properties -%}
|
| 831 |
+
{%- set found = namespace(value='false') -%}
|
| 832 |
+
{%- for child_name, child_spec in spec.properties | items -%}
|
| 833 |
+
{%- if schema_has_combinator(child_spec) == 'true' -%}
|
| 834 |
+
{%- set found.value = 'true' -%}
|
| 835 |
+
{%- endif -%}
|
| 836 |
+
{%- endfor -%}
|
| 837 |
+
{{- found.value -}}
|
| 838 |
+
{%- else -%}
|
| 839 |
+
false
|
| 840 |
+
{%- endif -%}
|
| 841 |
+
{%- endmacro -%}
|
| 842 |
+
|
| 843 |
+
{%- macro render_arg_type(tools_list, tool_name, arg_name, value) -%}
|
| 844 |
+
{%- set found = namespace(type='any') -%}
|
| 845 |
+
{%- for tool in tools_list -%}
|
| 846 |
+
{%- set fn = tool.function if tool.function is defined else tool -%}
|
| 847 |
+
{%- if fn.name == tool_name and fn.parameters and fn.parameters.properties and arg_name in fn.parameters.properties -%}
|
| 848 |
+
{%- set spec = fn.parameters.properties[arg_name] -%}
|
| 849 |
+
{%- if spec is mapping and spec['$ref'] is string -%}
|
| 850 |
+
{%- set _r = spec['$ref'] -%}
|
| 851 |
+
{%- set _k = _r[8:] if _r.startswith('#/$defs/') else (_r[14:] if _r.startswith('#/definitions/') else none) -%}
|
| 852 |
+
{%- set _d = fn.parameters['$defs'] if fn.parameters['$defs'] is mapping else fn.parameters['definitions'] -%}
|
| 853 |
+
{%- set spec = dict((_d[_k] | items | list) + (spec | items | rejectattr('0', 'equalto', '$ref') | list)) if (_k is not none and _d is mapping and _d[_k] is mapping) else spec -%}
|
| 854 |
+
{%- endif -%}
|
| 855 |
+
{%- if schema_has_combinator(spec) == 'true' -%}
|
| 856 |
+
{%- set found.type = render_value_type(value) -%}
|
| 857 |
+
{%- else -%}
|
| 858 |
+
{%- set found.type = render_compact_type(spec) -%}
|
| 859 |
+
{%- endif -%}
|
| 860 |
+
{%- endif -%}
|
| 861 |
+
{%- endfor -%}
|
| 862 |
+
{{- found.type -}}
|
| 863 |
+
{%- endmacro -%}
|
| 864 |
+
|
| 865 |
+
{%- macro render_tool_calls_block(tool_calls, fmt, tools_list) -%}
|
| 866 |
+
{{- "<ifm|tool_calls>" }}
|
| 867 |
+
{%- for raw_tool_call in tool_calls -%}
|
| 868 |
+
{%- set tool_call = raw_tool_call.function if raw_tool_call.function else raw_tool_call -%}
|
| 869 |
+
{%- if tool_call.arguments is string -%}
|
| 870 |
+
{{- raise_exception("tool_call.arguments must be a dict, not a JSON string. Parse it before passing to the template.") -}}
|
| 871 |
+
{%- endif -%}
|
| 872 |
+
{%- if fmt == 'json' -%}
|
| 873 |
+
{{- "\n<ifm|tool_call>{\"name\": \"" + tool_call.name + "\", \"arguments\": " }}{{ tool_call.arguments | tojson }}{{- "}</ifm|tool_call>" }}
|
| 874 |
+
{%- elif fmt == 'xml' or fmt == 'xml_typed' -%}
|
| 875 |
+
{{- "\n<ifm|tool_call>" + tool_call.name + "\n" }}
|
| 876 |
+
{%- for key, value in tool_call.arguments | items -%}
|
| 877 |
+
{{- "<ifm|arg_key>" + key + "</ifm|arg_key>\n" }}
|
| 878 |
+
{%- if fmt == 'xml_typed' -%}
|
| 879 |
+
{{- "<ifm|arg_type>" + render_arg_type(tools_list, tool_call.name, key, value) + "</ifm|arg_type>\n" }}
|
| 880 |
+
{%- endif -%}
|
| 881 |
+
{{- "<ifm|arg_value>" }}{{ render_argument_value(value) }}{{- "</ifm|arg_value>\n" }}
|
| 882 |
+
{%- endfor -%}
|
| 883 |
+
{{- "</ifm|tool_call>" }}
|
| 884 |
+
{%- else -%}
|
| 885 |
+
{{- raise_exception("Unsupported tool_call_format: '" + fmt + "'. Supported formats: json, xml, xml_typed.") -}}
|
| 886 |
+
{%- endif -%}
|
| 887 |
+
{%- endfor -%}
|
| 888 |
+
{{- "\n</ifm|tool_calls>" }}
|
| 889 |
+
{%- endmacro -%}
|
| 890 |
+
|
| 891 |
+
{%- macro render_tool_response_messages(raw_content) -%}
|
| 892 |
+
{%- if raw_content is string -%}
|
| 893 |
+
{{- '<|ifm|im_start|>tool\n' + raw_content + '<|ifm|im_end|>' }}
|
| 894 |
+
{%- elif raw_content is sequence and raw_content is not string and raw_content is not mapping -%}
|
| 895 |
+
{%- if raw_content | length == 0 -%}
|
| 896 |
+
{{- raise_exception("tool message content list must not be empty.") -}}
|
| 897 |
+
{%- endif -%}
|
| 898 |
+
{{- '<|ifm|im_start|>tool\n' -}}
|
| 899 |
+
{%- for item in raw_content -%}
|
| 900 |
+
{%- if not loop.first -%}{{- '\n' -}}{%- endif -%}
|
| 901 |
+
{%- if item is string -%}
|
| 902 |
+
{{- item -}}
|
| 903 |
+
{%- elif item is mapping and item.text is string -%}
|
| 904 |
+
{{- item.text -}}
|
| 905 |
+
{%- else -%}
|
| 906 |
+
{{- (item | tojson) -}}
|
| 907 |
+
{%- endif -%}
|
| 908 |
+
{%- endfor -%}
|
| 909 |
+
{{- '<|ifm|im_end|>' -}}
|
| 910 |
+
{%- else -%}
|
| 911 |
+
{{- '<|ifm|im_start|>tool\n' }}{{ raw_content | tojson }}{{- '<|ifm|im_end|>' }}
|
| 912 |
+
{%- endif -%}
|
| 913 |
+
{%- endmacro -%}
|
| 914 |
+
|
| 915 |
+
{%- set available_tools = tools if tools else [] -%}
|
| 916 |
+
{%- if (not available_tools) and messages[0].role == 'system' and messages[0].get('tools') -%}
|
| 917 |
+
{%- set available_tools = messages[0]['tools'] -%}
|
| 918 |
+
{%- endif -%}
|
| 919 |
+
{%- if available_tools -%}
|
| 920 |
+
{{- validate_tools(available_tools, tool_presentation_fmt != 'json') }}
|
| 921 |
+
{%- set system_content = '' -%}
|
| 922 |
+
{%- if messages[0].role == 'system' and messages[0].content -%}
|
| 923 |
+
{%- set system_content = messages[0].content -%}
|
| 924 |
+
{%- endif -%}
|
| 925 |
+
{{- render_system_with_tools(available_tools, system_content, tool_presentation_fmt, tool_call_fmt) }}
|
| 926 |
+
{%- else -%}
|
| 927 |
+
{%- if messages[0].role == 'system' -%}
|
| 928 |
+
{{- '<|ifm|im_start|>system\n' + messages[0].content + '<|ifm|im_end|>' }}
|
| 929 |
+
{%- endif -%}
|
| 930 |
+
{%- endif -%}
|
| 931 |
+
|
| 932 |
+
{%- for message in messages -%}
|
| 933 |
+
{%- if message.content is string -%}
|
| 934 |
+
{%- set content = message.content -%}
|
| 935 |
+
{%- else -%}
|
| 936 |
+
{%- set content = '' -%}
|
| 937 |
+
{%- endif -%}
|
| 938 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) -%}
|
| 939 |
+
{{- '<|ifm|im_start|>' + message.role + '\n' + content + '<|ifm|im_end|>' }}
|
| 940 |
+
{%- elif message.role == "assistant" -%}
|
| 941 |
+
{%- set thinking_content = '' -%}
|
| 942 |
+
{%- set think_tag = 'ifm|think' -%}
|
| 943 |
+
{%- if message.think is defined and message.think is string -%}
|
| 944 |
+
{%- set thinking_content = message.think -%}
|
| 945 |
+
{%- set think_tag = 'ifm|think' -%}
|
| 946 |
+
{%- elif message.think_fast is defined and message.think_fast is string -%}
|
| 947 |
+
{%- set thinking_content = message.think_fast -%}
|
| 948 |
+
{%- set think_tag = 'ifm|think_fast' -%}
|
| 949 |
+
{%- elif message.think_faster is defined and message.think_faster is string -%}
|
| 950 |
+
{%- set thinking_content = message.think_faster -%}
|
| 951 |
+
{%- set think_tag = 'ifm|think_faster' -%}
|
| 952 |
+
{%- elif message.reasoning_content is defined and message.reasoning_content is string -%}
|
| 953 |
+
{%- set thinking_content = message.reasoning_content -%}
|
| 954 |
+
{%- set think_tag = 'ifm|think' -%}
|
| 955 |
+
{%- elif message.reasoning is defined and message.reasoning is string -%}
|
| 956 |
+
{%- set thinking_content = message.reasoning -%}
|
| 957 |
+
{%- set think_tag = 'ifm|think' -%}
|
| 958 |
+
{%- elif message.think is not defined and message.reasoning is not defined and message.reasoning_content is not defined and message.think_fast is not defined and message.think_faster is not defined -%}
|
| 959 |
+
{{- raise_exception("Assistant message is missing a thinking field. Provide one of: think, reasoning, reasoning_content, think_fast, think_faster.") -}}
|
| 960 |
+
{%- else -%}
|
| 961 |
+
{{- raise_exception("Assistant thinking fields must be strings. Provide one of: think, reasoning, reasoning_content, think_fast, think_faster as a string.") -}}
|
| 962 |
+
{%- endif -%}
|
| 963 |
+
{{- '<|ifm|im_start|>' + message.role }}
|
| 964 |
+
{% generation %}
|
| 965 |
+
{%- if think_tag -%}
|
| 966 |
+
{%- if thinking_content -%}
|
| 967 |
+
{{- '<' + think_tag + '>\n' + thinking_content + '</' + think_tag + '>' + content }}
|
| 968 |
+
{%- else -%}
|
| 969 |
+
{{- '<' + think_tag + '>\n</' + think_tag + '>' + content }}
|
| 970 |
+
{%- endif -%}
|
| 971 |
+
{%- else -%}
|
| 972 |
+
{{- content }}
|
| 973 |
+
{%- endif -%}
|
| 974 |
+
{%- if message.tool_calls -%}
|
| 975 |
+
{{- render_tool_calls_block(message.tool_calls, tool_call_fmt, available_tools) }}
|
| 976 |
+
{%- endif -%}
|
| 977 |
+
{{- '<|ifm|im_end|>' -}}
|
| 978 |
+
{%- endgeneration -%}
|
| 979 |
+
{%- elif message.role == "tool" -%}
|
| 980 |
+
{{- render_tool_response_messages(message.content) }}
|
| 981 |
+
{%- endif -%}
|
| 982 |
+
{%- endfor -%}
|
| 983 |
+
{%- if add_generation_prompt -%}
|
| 984 |
+
{%- set effort = reasoning_effort | default('high') -%}
|
| 985 |
+
{%- if effort == 'high' -%}
|
| 986 |
+
{{- '<|ifm|im_start|>assistant\n<ifm|think>\n' }}
|
| 987 |
+
{%- elif effort == 'medium' -%}
|
| 988 |
+
{{- '<|ifm|im_start|>assistant\n<ifm|think_fast>\n' }}
|
| 989 |
+
{%- elif effort == 'low' -%}
|
| 990 |
+
{{- '<|ifm|im_start|>assistant\n<ifm|think_faster>\n' }}
|
| 991 |
+
{%- else -%}
|
| 992 |
+
{{- raise_exception("Unsupported reasoning_effort: '" + effort + "'. Supported values: high, medium, low.") -}}
|
| 993 |
+
{%- endif -%}
|
| 994 |
+
{%- endif -%}
|
config.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"K2HorizonForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"attention_gate_func": null,
|
| 8 |
+
"auto_map": {
|
| 9 |
+
"AutoConfig": "configuration_k2_horizon.K2HorizonConfig",
|
| 10 |
+
"AutoModel": "modeling_k2_horizon.K2HorizonModel",
|
| 11 |
+
"AutoModelForCausalLM": "modeling_k2_horizon.K2HorizonForCausalLM"
|
| 12 |
+
},
|
| 13 |
+
"bos_token_id": 0,
|
| 14 |
+
"decoder_sparse_step": 1,
|
| 15 |
+
"dtype": "bfloat16",
|
| 16 |
+
"eos_token_id": [
|
| 17 |
+
1,
|
| 18 |
+
250019
|
| 19 |
+
],
|
| 20 |
+
"head_dim": 128,
|
| 21 |
+
"hidden_act": "silu",
|
| 22 |
+
"hidden_size": 2560,
|
| 23 |
+
"initializer_range": 0.02,
|
| 24 |
+
"intermediate_size": 10240,
|
| 25 |
+
"layernorm_num_groups": 2,
|
| 26 |
+
"max_position_embeddings": 524288,
|
| 27 |
+
"mlp_only_layers": [
|
| 28 |
+
0,
|
| 29 |
+
1,
|
| 30 |
+
2,
|
| 31 |
+
3,
|
| 32 |
+
4,
|
| 33 |
+
5,
|
| 34 |
+
6,
|
| 35 |
+
7,
|
| 36 |
+
8,
|
| 37 |
+
9,
|
| 38 |
+
10,
|
| 39 |
+
11,
|
| 40 |
+
12,
|
| 41 |
+
13,
|
| 42 |
+
14,
|
| 43 |
+
15,
|
| 44 |
+
16,
|
| 45 |
+
17,
|
| 46 |
+
18,
|
| 47 |
+
19,
|
| 48 |
+
20,
|
| 49 |
+
21,
|
| 50 |
+
22,
|
| 51 |
+
23,
|
| 52 |
+
24,
|
| 53 |
+
25,
|
| 54 |
+
26,
|
| 55 |
+
27,
|
| 56 |
+
28,
|
| 57 |
+
29,
|
| 58 |
+
30,
|
| 59 |
+
31,
|
| 60 |
+
32,
|
| 61 |
+
33,
|
| 62 |
+
34,
|
| 63 |
+
35
|
| 64 |
+
],
|
| 65 |
+
"model_type": "k2_horizon",
|
| 66 |
+
"moe_gate_bias": false,
|
| 67 |
+
"moe_intermediate_size": 0,
|
| 68 |
+
"mova_num_experts": 0,
|
| 69 |
+
"mova_num_experts_per_tok": 0,
|
| 70 |
+
"norm_topk_prob": true,
|
| 71 |
+
"num_attention_heads": 32,
|
| 72 |
+
"num_experts": 0,
|
| 73 |
+
"num_experts_per_tok": 0,
|
| 74 |
+
"num_hidden_layers": 36,
|
| 75 |
+
"num_key_value_heads": 8,
|
| 76 |
+
"num_shared_experts": 0,
|
| 77 |
+
"output_router_logits": false,
|
| 78 |
+
"pad_token_id": null,
|
| 79 |
+
"quantization": {
|
| 80 |
+
"group_size": 64,
|
| 81 |
+
"bits": 4,
|
| 82 |
+
"mode": "affine"
|
| 83 |
+
},
|
| 84 |
+
"quantization_config": {
|
| 85 |
+
"group_size": 64,
|
| 86 |
+
"bits": 4,
|
| 87 |
+
"mode": "affine"
|
| 88 |
+
},
|
| 89 |
+
"query_key_norm": false,
|
| 90 |
+
"rms_norm_eps": 1e-06,
|
| 91 |
+
"rope_head_dim": 128,
|
| 92 |
+
"rope_scaling": null,
|
| 93 |
+
"rope_theta": 10000000.0,
|
| 94 |
+
"router_aux_loss_coef": 0.001,
|
| 95 |
+
"router_scaling_factor": 1.0,
|
| 96 |
+
"router_score_func": "sigmoid",
|
| 97 |
+
"sliding_window": null,
|
| 98 |
+
"tie_word_embeddings": false,
|
| 99 |
+
"transformers_version": "5.13.0",
|
| 100 |
+
"use_cache": true,
|
| 101 |
+
"use_sliding_window": false,
|
| 102 |
+
"vocab_size": 250624,
|
| 103 |
+
"model_file": "k2_horizon_mlx.py"
|
| 104 |
+
}
|
configuration_k2_horizon.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""K2Horizon model configuration"""
|
| 15 |
+
|
| 16 |
+
from huggingface_hub.dataclasses import strict
|
| 17 |
+
|
| 18 |
+
from transformers.configuration_utils import PreTrainedConfig
|
| 19 |
+
from transformers.modeling_rope_utils import RopeParameters
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@strict
|
| 23 |
+
class K2HorizonConfig(PreTrainedConfig):
|
| 24 |
+
r"""
|
| 25 |
+
decoder_sparse_step (`int`, *optional*, defaults to 1):
|
| 26 |
+
The frequency of the MoE layer.
|
| 27 |
+
mlp_only_layers (`list[int]`, *optional*, defaults to `[]`):
|
| 28 |
+
Indicate which layers use K2HorizonMLP rather than K2HorizonSparseMoeBlock
|
| 29 |
+
The list contains layer index, from 0 to num_layers-1 if we have num_layers layers
|
| 30 |
+
If `mlp_only_layers` is empty, `decoder_sparse_step` is used to determine the sparsity.
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
>>> from transformers import K2HorizonModel, K2HorizonConfig
|
| 34 |
+
|
| 35 |
+
>>> # Initializing a K2Horizon style configuration
|
| 36 |
+
>>> configuration = K2HorizonConfig()
|
| 37 |
+
>>> model = K2HorizonModel(configuration)
|
| 38 |
+
|
| 39 |
+
>>> # Accessing the model configuration
|
| 40 |
+
>>> configuration = model.config
|
| 41 |
+
```
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
model_type = "k2_horizon"
|
| 45 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 46 |
+
|
| 47 |
+
vocab_size: int = 151936
|
| 48 |
+
hidden_size: int = 2048
|
| 49 |
+
intermediate_size: int = 6144
|
| 50 |
+
num_hidden_layers: int = 24
|
| 51 |
+
num_attention_heads: int = 32
|
| 52 |
+
num_key_value_heads: int = 4
|
| 53 |
+
hidden_act: str = "silu"
|
| 54 |
+
max_position_embeddings: int = 32768
|
| 55 |
+
initializer_range: float = 0.02
|
| 56 |
+
rms_norm_eps: float = 1e-6
|
| 57 |
+
use_cache: bool = True
|
| 58 |
+
tie_word_embeddings: bool = False
|
| 59 |
+
rope_parameters: RopeParameters | dict | None = None
|
| 60 |
+
attention_bias: bool = False
|
| 61 |
+
use_sliding_window: bool = False
|
| 62 |
+
sliding_window: int | None = 4096
|
| 63 |
+
attention_dropout: float | int = 0.0
|
| 64 |
+
decoder_sparse_step: int = 1
|
| 65 |
+
moe_intermediate_size: int = 768
|
| 66 |
+
num_experts_per_tok: int = 8
|
| 67 |
+
num_experts: int = 128
|
| 68 |
+
norm_topk_prob: bool = False
|
| 69 |
+
output_router_logits: bool = False
|
| 70 |
+
router_aux_loss_coef: float = 0.001
|
| 71 |
+
mlp_only_layers: list[int] | None = None
|
| 72 |
+
pad_token_id: int | None = None
|
| 73 |
+
bos_token_id: int | None = None
|
| 74 |
+
eos_token_id: int | list[int] | None = None
|
| 75 |
+
|
| 76 |
+
head_dim: int = 128
|
| 77 |
+
query_key_norm: bool = True
|
| 78 |
+
moe_gate_bias: bool = False
|
| 79 |
+
layernorm_num_groups: int = 1
|
| 80 |
+
num_shared_experts: int = 0
|
| 81 |
+
router_score_func: str = "softmax"
|
| 82 |
+
router_scaling_factor: float | None = 1.0
|
| 83 |
+
rope_head_dim: int | None = None
|
| 84 |
+
attention_gate_func: str | None = None
|
| 85 |
+
mova_num_experts: int = 0
|
| 86 |
+
mova_num_experts_per_tok: int = 0
|
| 87 |
+
|
| 88 |
+
def __post_init__(self, **kwargs):
|
| 89 |
+
self.sliding_window = self.sliding_window if self.use_sliding_window else None
|
| 90 |
+
self.mlp_only_layers = [] if self.mlp_only_layers is None else self.mlp_only_layers
|
| 91 |
+
if self.router_scaling_factor is None:
|
| 92 |
+
self.router_scaling_factor = 1.0
|
| 93 |
+
super().__post_init__(**kwargs)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
__all__ = ["K2HorizonConfig"]
|
generation_config.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""MLX-LM adapter for the dense K2 Horizon configuration.
|
| 2 |
+
|
| 3 |
+
K2 Horizon uses the Llama-style decoder/attention layout, but its RMSNorm
|
| 4 |
+
normalizes two groups of the hidden dimension independently. This module
|
| 5 |
+
keeps that detail instead of silently treating the checkpoint as Llama.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from typing import Any, Dict, List, Optional, Union
|
| 10 |
+
|
| 11 |
+
import mlx.core as mx
|
| 12 |
+
import mlx.nn as nn
|
| 13 |
+
|
| 14 |
+
from mlx_lm.models.activations import swiglu
|
| 15 |
+
from mlx_lm.models.base import BaseModelArgs, create_attention_mask, scaled_dot_product_attention
|
| 16 |
+
from mlx_lm.models.cache import KVCache, RotatingKVCache
|
| 17 |
+
from mlx_lm.models.rope_utils import initialize_rope
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@dataclass
|
| 21 |
+
class ModelArgs(BaseModelArgs):
|
| 22 |
+
model_type: str
|
| 23 |
+
hidden_size: int
|
| 24 |
+
num_hidden_layers: int
|
| 25 |
+
intermediate_size: int
|
| 26 |
+
num_attention_heads: int
|
| 27 |
+
rms_norm_eps: float
|
| 28 |
+
vocab_size: int
|
| 29 |
+
num_key_value_heads: Optional[int] = None
|
| 30 |
+
head_dim: Optional[int] = None
|
| 31 |
+
max_position_embeddings: Optional[int] = None
|
| 32 |
+
# K2 stores RoPE settings under rope_parameters; this is the model default.
|
| 33 |
+
rope_theta: float = 10_000_000.0
|
| 34 |
+
rope_traditional: bool = False
|
| 35 |
+
rope_scaling: Optional[Dict[str, Union[float, str]]] = None
|
| 36 |
+
tie_word_embeddings: bool = False
|
| 37 |
+
attention_bias: bool = False
|
| 38 |
+
mlp_bias: bool = False
|
| 39 |
+
layernorm_num_groups: int = 2
|
| 40 |
+
sliding_window: Optional[int] = None
|
| 41 |
+
layer_types: Optional[List[str]] = None
|
| 42 |
+
|
| 43 |
+
def __post_init__(self):
|
| 44 |
+
if self.num_key_value_heads is None:
|
| 45 |
+
self.num_key_value_heads = self.num_attention_heads
|
| 46 |
+
if self.head_dim is None:
|
| 47 |
+
self.head_dim = self.hidden_size // self.num_attention_heads
|
| 48 |
+
if self.layer_types is None:
|
| 49 |
+
self.layer_types = ["full_attention"] * self.num_hidden_layers
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class GroupRMSNorm(nn.Module):
|
| 53 |
+
"""K2's T5-style grouped RMS normalization."""
|
| 54 |
+
|
| 55 |
+
def __init__(self, dims: int, eps: float, groups: int):
|
| 56 |
+
super().__init__()
|
| 57 |
+
if dims % groups:
|
| 58 |
+
raise ValueError(f"hidden size {dims} is not divisible by {groups} groups")
|
| 59 |
+
self.weight = mx.ones((dims,))
|
| 60 |
+
self.groups = groups
|
| 61 |
+
self.eps = eps
|
| 62 |
+
|
| 63 |
+
def __call__(self, x: mx.array) -> mx.array:
|
| 64 |
+
x = mx.unflatten(x, axis=-1, shape=(self.groups, -1))
|
| 65 |
+
x = mx.fast.rms_norm(x, weight=None, eps=self.eps)
|
| 66 |
+
return self.weight * mx.flatten(x, -2)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class Attention(nn.Module):
|
| 70 |
+
def __init__(self, args: ModelArgs):
|
| 71 |
+
super().__init__()
|
| 72 |
+
dim = args.hidden_size
|
| 73 |
+
self.n_heads = args.num_attention_heads
|
| 74 |
+
self.n_kv_heads = args.num_key_value_heads
|
| 75 |
+
self.head_dim = args.head_dim
|
| 76 |
+
self.scale = self.head_dim**-0.5
|
| 77 |
+
bias = args.attention_bias
|
| 78 |
+
self.q_proj = nn.Linear(dim, self.n_heads * self.head_dim, bias=bias)
|
| 79 |
+
self.k_proj = nn.Linear(dim, self.n_kv_heads * self.head_dim, bias=bias)
|
| 80 |
+
self.v_proj = nn.Linear(dim, self.n_kv_heads * self.head_dim, bias=bias)
|
| 81 |
+
self.o_proj = nn.Linear(self.n_heads * self.head_dim, dim, bias=bias)
|
| 82 |
+
self.rope = initialize_rope(
|
| 83 |
+
self.head_dim,
|
| 84 |
+
args.rope_theta,
|
| 85 |
+
args.rope_traditional,
|
| 86 |
+
args.rope_scaling,
|
| 87 |
+
args.max_position_embeddings,
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
def __call__(self, x: mx.array, mask=None, cache=None) -> mx.array:
|
| 91 |
+
B, L, _ = x.shape
|
| 92 |
+
q = self.q_proj(x).reshape(B, L, self.n_heads, self.head_dim).transpose(0, 2, 1, 3)
|
| 93 |
+
k = self.k_proj(x).reshape(B, L, self.n_kv_heads, self.head_dim).transpose(0, 2, 1, 3)
|
| 94 |
+
v = self.v_proj(x).reshape(B, L, self.n_kv_heads, self.head_dim).transpose(0, 2, 1, 3)
|
| 95 |
+
offset = cache.offset if cache is not None else 0
|
| 96 |
+
q = self.rope(q, offset=offset)
|
| 97 |
+
k = self.rope(k, offset=offset)
|
| 98 |
+
if cache is not None:
|
| 99 |
+
k, v = cache.update_and_fetch(k, v)
|
| 100 |
+
out = scaled_dot_product_attention(q, k, v, cache=cache, scale=self.scale, mask=mask)
|
| 101 |
+
out = out.transpose(0, 2, 1, 3).reshape(B, L, -1)
|
| 102 |
+
return self.o_proj(out)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class MLP(nn.Module):
|
| 106 |
+
def __init__(self, args: ModelArgs):
|
| 107 |
+
super().__init__()
|
| 108 |
+
self.gate_proj = nn.Linear(args.hidden_size, args.intermediate_size, bias=args.mlp_bias)
|
| 109 |
+
self.down_proj = nn.Linear(args.intermediate_size, args.hidden_size, bias=args.mlp_bias)
|
| 110 |
+
self.up_proj = nn.Linear(args.hidden_size, args.intermediate_size, bias=args.mlp_bias)
|
| 111 |
+
|
| 112 |
+
def __call__(self, x):
|
| 113 |
+
return self.down_proj(swiglu(self.gate_proj(x), self.up_proj(x)))
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
class TransformerBlock(nn.Module):
|
| 117 |
+
def __init__(self, args: ModelArgs, use_sliding: bool = False):
|
| 118 |
+
super().__init__()
|
| 119 |
+
self.self_attn = Attention(args)
|
| 120 |
+
self.mlp = MLP(args)
|
| 121 |
+
self.input_layernorm = GroupRMSNorm(
|
| 122 |
+
args.hidden_size, args.rms_norm_eps, args.layernorm_num_groups
|
| 123 |
+
)
|
| 124 |
+
self.post_attention_layernorm = GroupRMSNorm(
|
| 125 |
+
args.hidden_size, args.rms_norm_eps, args.layernorm_num_groups
|
| 126 |
+
)
|
| 127 |
+
self.use_sliding = use_sliding
|
| 128 |
+
|
| 129 |
+
def __call__(self, x, mask=None, cache=None):
|
| 130 |
+
h = x + self.self_attn(self.input_layernorm(x), mask, cache)
|
| 131 |
+
return h + self.mlp(self.post_attention_layernorm(h))
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
class K2HorizonModel(nn.Module):
|
| 135 |
+
def __init__(self, args: ModelArgs):
|
| 136 |
+
super().__init__()
|
| 137 |
+
self.args = args
|
| 138 |
+
self.vocab_size = args.vocab_size
|
| 139 |
+
self.embed_tokens = nn.Embedding(args.vocab_size, args.hidden_size)
|
| 140 |
+
self.layers = [
|
| 141 |
+
TransformerBlock(args, use_sliding=t == "sliding_attention")
|
| 142 |
+
for t in args.layer_types
|
| 143 |
+
]
|
| 144 |
+
self.norm = GroupRMSNorm(args.hidden_size, args.rms_norm_eps, args.layernorm_num_groups)
|
| 145 |
+
self.sliding_window = args.sliding_window
|
| 146 |
+
self.fa_idx = 0
|
| 147 |
+
self.swa_idx = None
|
| 148 |
+
for i, layer in enumerate(self.layers):
|
| 149 |
+
if layer.use_sliding:
|
| 150 |
+
self.swa_idx = i
|
| 151 |
+
break
|
| 152 |
+
|
| 153 |
+
def __call__(self, inputs, cache=None, input_embeddings=None):
|
| 154 |
+
h = self.embed_tokens(inputs) if input_embeddings is None else input_embeddings
|
| 155 |
+
if cache is None:
|
| 156 |
+
cache = [None] * len(self.layers)
|
| 157 |
+
fa_mask = create_attention_mask(h, cache[self.fa_idx])
|
| 158 |
+
swa_mask = None
|
| 159 |
+
if self.swa_idx is not None:
|
| 160 |
+
swa_mask = create_attention_mask(
|
| 161 |
+
h, cache[self.swa_idx], window_size=self.sliding_window
|
| 162 |
+
)
|
| 163 |
+
for layer, c in zip(self.layers, cache):
|
| 164 |
+
h = layer(h, swa_mask if layer.use_sliding else fa_mask, c)
|
| 165 |
+
return self.norm(h)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class Model(nn.Module):
|
| 169 |
+
def __init__(self, args: ModelArgs):
|
| 170 |
+
super().__init__()
|
| 171 |
+
self.args = args
|
| 172 |
+
self.model_type = args.model_type
|
| 173 |
+
self.model = K2HorizonModel(args)
|
| 174 |
+
if not args.tie_word_embeddings:
|
| 175 |
+
self.lm_head = nn.Linear(args.hidden_size, args.vocab_size, bias=False)
|
| 176 |
+
|
| 177 |
+
def __call__(self, inputs, cache=None, input_embeddings=None):
|
| 178 |
+
h = self.model(inputs, cache, input_embeddings)
|
| 179 |
+
return self.lm_head(h)
|
| 180 |
+
|
| 181 |
+
def sanitize(self, weights):
|
| 182 |
+
return {
|
| 183 |
+
k: v
|
| 184 |
+
for k, v in weights.items()
|
| 185 |
+
if "rotary_emb.inv_freq" not in k
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
@property
|
| 189 |
+
def layers(self):
|
| 190 |
+
return self.model.layers
|
| 191 |
+
|
| 192 |
+
def make_cache(self):
|
| 193 |
+
return [
|
| 194 |
+
RotatingKVCache(max_size=self.model.sliding_window)
|
| 195 |
+
if layer.use_sliding
|
| 196 |
+
else KVCache()
|
| 197 |
+
for layer in self.model.layers
|
| 198 |
+
]
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f2155c94d950cbc6d55929b0e46b114a912e211d006ae89bc7ed987b4b1cd2e8
|
| 3 |
+
size 2845632490
|
model.safetensors.index.json
ADDED
|
@@ -0,0 +1,843 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 2845537280,
|
| 4 |
+
"total_parameters": 5058255360
|
| 5 |
+
},
|
| 6 |
+
"weight_map": {
|
| 7 |
+
"lm_head.biases": "model.safetensors",
|
| 8 |
+
"lm_head.scales": "model.safetensors",
|
| 9 |
+
"lm_head.weight": "model.safetensors",
|
| 10 |
+
"model.embed_tokens.biases": "model.safetensors",
|
| 11 |
+
"model.embed_tokens.scales": "model.safetensors",
|
| 12 |
+
"model.embed_tokens.weight": "model.safetensors",
|
| 13 |
+
"model.layers.0.input_layernorm.weight": "model.safetensors",
|
| 14 |
+
"model.layers.0.mlp.down_proj.biases": "model.safetensors",
|
| 15 |
+
"model.layers.0.mlp.down_proj.scales": "model.safetensors",
|
| 16 |
+
"model.layers.0.mlp.down_proj.weight": "model.safetensors",
|
| 17 |
+
"model.layers.0.mlp.gate_proj.biases": "model.safetensors",
|
| 18 |
+
"model.layers.0.mlp.gate_proj.scales": "model.safetensors",
|
| 19 |
+
"model.layers.0.mlp.gate_proj.weight": "model.safetensors",
|
| 20 |
+
"model.layers.0.mlp.up_proj.biases": "model.safetensors",
|
| 21 |
+
"model.layers.0.mlp.up_proj.scales": "model.safetensors",
|
| 22 |
+
"model.layers.0.mlp.up_proj.weight": "model.safetensors",
|
| 23 |
+
"model.layers.0.post_attention_layernorm.weight": "model.safetensors",
|
| 24 |
+
"model.layers.0.self_attn.k_proj.biases": "model.safetensors",
|
| 25 |
+
"model.layers.0.self_attn.k_proj.scales": "model.safetensors",
|
| 26 |
+
"model.layers.0.self_attn.k_proj.weight": "model.safetensors",
|
| 27 |
+
"model.layers.0.self_attn.o_proj.biases": "model.safetensors",
|
| 28 |
+
"model.layers.0.self_attn.o_proj.scales": "model.safetensors",
|
| 29 |
+
"model.layers.0.self_attn.o_proj.weight": "model.safetensors",
|
| 30 |
+
"model.layers.0.self_attn.q_proj.biases": "model.safetensors",
|
| 31 |
+
"model.layers.0.self_attn.q_proj.scales": "model.safetensors",
|
| 32 |
+
"model.layers.0.self_attn.q_proj.weight": "model.safetensors",
|
| 33 |
+
"model.layers.0.self_attn.v_proj.biases": "model.safetensors",
|
| 34 |
+
"model.layers.0.self_attn.v_proj.scales": "model.safetensors",
|
| 35 |
+
"model.layers.0.self_attn.v_proj.weight": "model.safetensors",
|
| 36 |
+
"model.layers.1.input_layernorm.weight": "model.safetensors",
|
| 37 |
+
"model.layers.1.mlp.down_proj.biases": "model.safetensors",
|
| 38 |
+
"model.layers.1.mlp.down_proj.scales": "model.safetensors",
|
| 39 |
+
"model.layers.1.mlp.down_proj.weight": "model.safetensors",
|
| 40 |
+
"model.layers.1.mlp.gate_proj.biases": "model.safetensors",
|
| 41 |
+
"model.layers.1.mlp.gate_proj.scales": "model.safetensors",
|
| 42 |
+
"model.layers.1.mlp.gate_proj.weight": "model.safetensors",
|
| 43 |
+
"model.layers.1.mlp.up_proj.biases": "model.safetensors",
|
| 44 |
+
"model.layers.1.mlp.up_proj.scales": "model.safetensors",
|
| 45 |
+
"model.layers.1.mlp.up_proj.weight": "model.safetensors",
|
| 46 |
+
"model.layers.1.post_attention_layernorm.weight": "model.safetensors",
|
| 47 |
+
"model.layers.1.self_attn.k_proj.biases": "model.safetensors",
|
| 48 |
+
"model.layers.1.self_attn.k_proj.scales": "model.safetensors",
|
| 49 |
+
"model.layers.1.self_attn.k_proj.weight": "model.safetensors",
|
| 50 |
+
"model.layers.1.self_attn.o_proj.biases": "model.safetensors",
|
| 51 |
+
"model.layers.1.self_attn.o_proj.scales": "model.safetensors",
|
| 52 |
+
"model.layers.1.self_attn.o_proj.weight": "model.safetensors",
|
| 53 |
+
"model.layers.1.self_attn.q_proj.biases": "model.safetensors",
|
| 54 |
+
"model.layers.1.self_attn.q_proj.scales": "model.safetensors",
|
| 55 |
+
"model.layers.1.self_attn.q_proj.weight": "model.safetensors",
|
| 56 |
+
"model.layers.1.self_attn.v_proj.biases": "model.safetensors",
|
| 57 |
+
"model.layers.1.self_attn.v_proj.scales": "model.safetensors",
|
| 58 |
+
"model.layers.1.self_attn.v_proj.weight": "model.safetensors",
|
| 59 |
+
"model.layers.10.input_layernorm.weight": "model.safetensors",
|
| 60 |
+
"model.layers.10.mlp.down_proj.biases": "model.safetensors",
|
| 61 |
+
"model.layers.10.mlp.down_proj.scales": "model.safetensors",
|
| 62 |
+
"model.layers.10.mlp.down_proj.weight": "model.safetensors",
|
| 63 |
+
"model.layers.10.mlp.gate_proj.biases": "model.safetensors",
|
| 64 |
+
"model.layers.10.mlp.gate_proj.scales": "model.safetensors",
|
| 65 |
+
"model.layers.10.mlp.gate_proj.weight": "model.safetensors",
|
| 66 |
+
"model.layers.10.mlp.up_proj.biases": "model.safetensors",
|
| 67 |
+
"model.layers.10.mlp.up_proj.scales": "model.safetensors",
|
| 68 |
+
"model.layers.10.mlp.up_proj.weight": "model.safetensors",
|
| 69 |
+
"model.layers.10.post_attention_layernorm.weight": "model.safetensors",
|
| 70 |
+
"model.layers.10.self_attn.k_proj.biases": "model.safetensors",
|
| 71 |
+
"model.layers.10.self_attn.k_proj.scales": "model.safetensors",
|
| 72 |
+
"model.layers.10.self_attn.k_proj.weight": "model.safetensors",
|
| 73 |
+
"model.layers.10.self_attn.o_proj.biases": "model.safetensors",
|
| 74 |
+
"model.layers.10.self_attn.o_proj.scales": "model.safetensors",
|
| 75 |
+
"model.layers.10.self_attn.o_proj.weight": "model.safetensors",
|
| 76 |
+
"model.layers.10.self_attn.q_proj.biases": "model.safetensors",
|
| 77 |
+
"model.layers.10.self_attn.q_proj.scales": "model.safetensors",
|
| 78 |
+
"model.layers.10.self_attn.q_proj.weight": "model.safetensors",
|
| 79 |
+
"model.layers.10.self_attn.v_proj.biases": "model.safetensors",
|
| 80 |
+
"model.layers.10.self_attn.v_proj.scales": "model.safetensors",
|
| 81 |
+
"model.layers.10.self_attn.v_proj.weight": "model.safetensors",
|
| 82 |
+
"model.layers.11.input_layernorm.weight": "model.safetensors",
|
| 83 |
+
"model.layers.11.mlp.down_proj.biases": "model.safetensors",
|
| 84 |
+
"model.layers.11.mlp.down_proj.scales": "model.safetensors",
|
| 85 |
+
"model.layers.11.mlp.down_proj.weight": "model.safetensors",
|
| 86 |
+
"model.layers.11.mlp.gate_proj.biases": "model.safetensors",
|
| 87 |
+
"model.layers.11.mlp.gate_proj.scales": "model.safetensors",
|
| 88 |
+
"model.layers.11.mlp.gate_proj.weight": "model.safetensors",
|
| 89 |
+
"model.layers.11.mlp.up_proj.biases": "model.safetensors",
|
| 90 |
+
"model.layers.11.mlp.up_proj.scales": "model.safetensors",
|
| 91 |
+
"model.layers.11.mlp.up_proj.weight": "model.safetensors",
|
| 92 |
+
"model.layers.11.post_attention_layernorm.weight": "model.safetensors",
|
| 93 |
+
"model.layers.11.self_attn.k_proj.biases": "model.safetensors",
|
| 94 |
+
"model.layers.11.self_attn.k_proj.scales": "model.safetensors",
|
| 95 |
+
"model.layers.11.self_attn.k_proj.weight": "model.safetensors",
|
| 96 |
+
"model.layers.11.self_attn.o_proj.biases": "model.safetensors",
|
| 97 |
+
"model.layers.11.self_attn.o_proj.scales": "model.safetensors",
|
| 98 |
+
"model.layers.11.self_attn.o_proj.weight": "model.safetensors",
|
| 99 |
+
"model.layers.11.self_attn.q_proj.biases": "model.safetensors",
|
| 100 |
+
"model.layers.11.self_attn.q_proj.scales": "model.safetensors",
|
| 101 |
+
"model.layers.11.self_attn.q_proj.weight": "model.safetensors",
|
| 102 |
+
"model.layers.11.self_attn.v_proj.biases": "model.safetensors",
|
| 103 |
+
"model.layers.11.self_attn.v_proj.scales": "model.safetensors",
|
| 104 |
+
"model.layers.11.self_attn.v_proj.weight": "model.safetensors",
|
| 105 |
+
"model.layers.12.input_layernorm.weight": "model.safetensors",
|
| 106 |
+
"model.layers.12.mlp.down_proj.biases": "model.safetensors",
|
| 107 |
+
"model.layers.12.mlp.down_proj.scales": "model.safetensors",
|
| 108 |
+
"model.layers.12.mlp.down_proj.weight": "model.safetensors",
|
| 109 |
+
"model.layers.12.mlp.gate_proj.biases": "model.safetensors",
|
| 110 |
+
"model.layers.12.mlp.gate_proj.scales": "model.safetensors",
|
| 111 |
+
"model.layers.12.mlp.gate_proj.weight": "model.safetensors",
|
| 112 |
+
"model.layers.12.mlp.up_proj.biases": "model.safetensors",
|
| 113 |
+
"model.layers.12.mlp.up_proj.scales": "model.safetensors",
|
| 114 |
+
"model.layers.12.mlp.up_proj.weight": "model.safetensors",
|
| 115 |
+
"model.layers.12.post_attention_layernorm.weight": "model.safetensors",
|
| 116 |
+
"model.layers.12.self_attn.k_proj.biases": "model.safetensors",
|
| 117 |
+
"model.layers.12.self_attn.k_proj.scales": "model.safetensors",
|
| 118 |
+
"model.layers.12.self_attn.k_proj.weight": "model.safetensors",
|
| 119 |
+
"model.layers.12.self_attn.o_proj.biases": "model.safetensors",
|
| 120 |
+
"model.layers.12.self_attn.o_proj.scales": "model.safetensors",
|
| 121 |
+
"model.layers.12.self_attn.o_proj.weight": "model.safetensors",
|
| 122 |
+
"model.layers.12.self_attn.q_proj.biases": "model.safetensors",
|
| 123 |
+
"model.layers.12.self_attn.q_proj.scales": "model.safetensors",
|
| 124 |
+
"model.layers.12.self_attn.q_proj.weight": "model.safetensors",
|
| 125 |
+
"model.layers.12.self_attn.v_proj.biases": "model.safetensors",
|
| 126 |
+
"model.layers.12.self_attn.v_proj.scales": "model.safetensors",
|
| 127 |
+
"model.layers.12.self_attn.v_proj.weight": "model.safetensors",
|
| 128 |
+
"model.layers.13.input_layernorm.weight": "model.safetensors",
|
| 129 |
+
"model.layers.13.mlp.down_proj.biases": "model.safetensors",
|
| 130 |
+
"model.layers.13.mlp.down_proj.scales": "model.safetensors",
|
| 131 |
+
"model.layers.13.mlp.down_proj.weight": "model.safetensors",
|
| 132 |
+
"model.layers.13.mlp.gate_proj.biases": "model.safetensors",
|
| 133 |
+
"model.layers.13.mlp.gate_proj.scales": "model.safetensors",
|
| 134 |
+
"model.layers.13.mlp.gate_proj.weight": "model.safetensors",
|
| 135 |
+
"model.layers.13.mlp.up_proj.biases": "model.safetensors",
|
| 136 |
+
"model.layers.13.mlp.up_proj.scales": "model.safetensors",
|
| 137 |
+
"model.layers.13.mlp.up_proj.weight": "model.safetensors",
|
| 138 |
+
"model.layers.13.post_attention_layernorm.weight": "model.safetensors",
|
| 139 |
+
"model.layers.13.self_attn.k_proj.biases": "model.safetensors",
|
| 140 |
+
"model.layers.13.self_attn.k_proj.scales": "model.safetensors",
|
| 141 |
+
"model.layers.13.self_attn.k_proj.weight": "model.safetensors",
|
| 142 |
+
"model.layers.13.self_attn.o_proj.biases": "model.safetensors",
|
| 143 |
+
"model.layers.13.self_attn.o_proj.scales": "model.safetensors",
|
| 144 |
+
"model.layers.13.self_attn.o_proj.weight": "model.safetensors",
|
| 145 |
+
"model.layers.13.self_attn.q_proj.biases": "model.safetensors",
|
| 146 |
+
"model.layers.13.self_attn.q_proj.scales": "model.safetensors",
|
| 147 |
+
"model.layers.13.self_attn.q_proj.weight": "model.safetensors",
|
| 148 |
+
"model.layers.13.self_attn.v_proj.biases": "model.safetensors",
|
| 149 |
+
"model.layers.13.self_attn.v_proj.scales": "model.safetensors",
|
| 150 |
+
"model.layers.13.self_attn.v_proj.weight": "model.safetensors",
|
| 151 |
+
"model.layers.14.input_layernorm.weight": "model.safetensors",
|
| 152 |
+
"model.layers.14.mlp.down_proj.biases": "model.safetensors",
|
| 153 |
+
"model.layers.14.mlp.down_proj.scales": "model.safetensors",
|
| 154 |
+
"model.layers.14.mlp.down_proj.weight": "model.safetensors",
|
| 155 |
+
"model.layers.14.mlp.gate_proj.biases": "model.safetensors",
|
| 156 |
+
"model.layers.14.mlp.gate_proj.scales": "model.safetensors",
|
| 157 |
+
"model.layers.14.mlp.gate_proj.weight": "model.safetensors",
|
| 158 |
+
"model.layers.14.mlp.up_proj.biases": "model.safetensors",
|
| 159 |
+
"model.layers.14.mlp.up_proj.scales": "model.safetensors",
|
| 160 |
+
"model.layers.14.mlp.up_proj.weight": "model.safetensors",
|
| 161 |
+
"model.layers.14.post_attention_layernorm.weight": "model.safetensors",
|
| 162 |
+
"model.layers.14.self_attn.k_proj.biases": "model.safetensors",
|
| 163 |
+
"model.layers.14.self_attn.k_proj.scales": "model.safetensors",
|
| 164 |
+
"model.layers.14.self_attn.k_proj.weight": "model.safetensors",
|
| 165 |
+
"model.layers.14.self_attn.o_proj.biases": "model.safetensors",
|
| 166 |
+
"model.layers.14.self_attn.o_proj.scales": "model.safetensors",
|
| 167 |
+
"model.layers.14.self_attn.o_proj.weight": "model.safetensors",
|
| 168 |
+
"model.layers.14.self_attn.q_proj.biases": "model.safetensors",
|
| 169 |
+
"model.layers.14.self_attn.q_proj.scales": "model.safetensors",
|
| 170 |
+
"model.layers.14.self_attn.q_proj.weight": "model.safetensors",
|
| 171 |
+
"model.layers.14.self_attn.v_proj.biases": "model.safetensors",
|
| 172 |
+
"model.layers.14.self_attn.v_proj.scales": "model.safetensors",
|
| 173 |
+
"model.layers.14.self_attn.v_proj.weight": "model.safetensors",
|
| 174 |
+
"model.layers.15.input_layernorm.weight": "model.safetensors",
|
| 175 |
+
"model.layers.15.mlp.down_proj.biases": "model.safetensors",
|
| 176 |
+
"model.layers.15.mlp.down_proj.scales": "model.safetensors",
|
| 177 |
+
"model.layers.15.mlp.down_proj.weight": "model.safetensors",
|
| 178 |
+
"model.layers.15.mlp.gate_proj.biases": "model.safetensors",
|
| 179 |
+
"model.layers.15.mlp.gate_proj.scales": "model.safetensors",
|
| 180 |
+
"model.layers.15.mlp.gate_proj.weight": "model.safetensors",
|
| 181 |
+
"model.layers.15.mlp.up_proj.biases": "model.safetensors",
|
| 182 |
+
"model.layers.15.mlp.up_proj.scales": "model.safetensors",
|
| 183 |
+
"model.layers.15.mlp.up_proj.weight": "model.safetensors",
|
| 184 |
+
"model.layers.15.post_attention_layernorm.weight": "model.safetensors",
|
| 185 |
+
"model.layers.15.self_attn.k_proj.biases": "model.safetensors",
|
| 186 |
+
"model.layers.15.self_attn.k_proj.scales": "model.safetensors",
|
| 187 |
+
"model.layers.15.self_attn.k_proj.weight": "model.safetensors",
|
| 188 |
+
"model.layers.15.self_attn.o_proj.biases": "model.safetensors",
|
| 189 |
+
"model.layers.15.self_attn.o_proj.scales": "model.safetensors",
|
| 190 |
+
"model.layers.15.self_attn.o_proj.weight": "model.safetensors",
|
| 191 |
+
"model.layers.15.self_attn.q_proj.biases": "model.safetensors",
|
| 192 |
+
"model.layers.15.self_attn.q_proj.scales": "model.safetensors",
|
| 193 |
+
"model.layers.15.self_attn.q_proj.weight": "model.safetensors",
|
| 194 |
+
"model.layers.15.self_attn.v_proj.biases": "model.safetensors",
|
| 195 |
+
"model.layers.15.self_attn.v_proj.scales": "model.safetensors",
|
| 196 |
+
"model.layers.15.self_attn.v_proj.weight": "model.safetensors",
|
| 197 |
+
"model.layers.16.input_layernorm.weight": "model.safetensors",
|
| 198 |
+
"model.layers.16.mlp.down_proj.biases": "model.safetensors",
|
| 199 |
+
"model.layers.16.mlp.down_proj.scales": "model.safetensors",
|
| 200 |
+
"model.layers.16.mlp.down_proj.weight": "model.safetensors",
|
| 201 |
+
"model.layers.16.mlp.gate_proj.biases": "model.safetensors",
|
| 202 |
+
"model.layers.16.mlp.gate_proj.scales": "model.safetensors",
|
| 203 |
+
"model.layers.16.mlp.gate_proj.weight": "model.safetensors",
|
| 204 |
+
"model.layers.16.mlp.up_proj.biases": "model.safetensors",
|
| 205 |
+
"model.layers.16.mlp.up_proj.scales": "model.safetensors",
|
| 206 |
+
"model.layers.16.mlp.up_proj.weight": "model.safetensors",
|
| 207 |
+
"model.layers.16.post_attention_layernorm.weight": "model.safetensors",
|
| 208 |
+
"model.layers.16.self_attn.k_proj.biases": "model.safetensors",
|
| 209 |
+
"model.layers.16.self_attn.k_proj.scales": "model.safetensors",
|
| 210 |
+
"model.layers.16.self_attn.k_proj.weight": "model.safetensors",
|
| 211 |
+
"model.layers.16.self_attn.o_proj.biases": "model.safetensors",
|
| 212 |
+
"model.layers.16.self_attn.o_proj.scales": "model.safetensors",
|
| 213 |
+
"model.layers.16.self_attn.o_proj.weight": "model.safetensors",
|
| 214 |
+
"model.layers.16.self_attn.q_proj.biases": "model.safetensors",
|
| 215 |
+
"model.layers.16.self_attn.q_proj.scales": "model.safetensors",
|
| 216 |
+
"model.layers.16.self_attn.q_proj.weight": "model.safetensors",
|
| 217 |
+
"model.layers.16.self_attn.v_proj.biases": "model.safetensors",
|
| 218 |
+
"model.layers.16.self_attn.v_proj.scales": "model.safetensors",
|
| 219 |
+
"model.layers.16.self_attn.v_proj.weight": "model.safetensors",
|
| 220 |
+
"model.layers.17.input_layernorm.weight": "model.safetensors",
|
| 221 |
+
"model.layers.17.mlp.down_proj.biases": "model.safetensors",
|
| 222 |
+
"model.layers.17.mlp.down_proj.scales": "model.safetensors",
|
| 223 |
+
"model.layers.17.mlp.down_proj.weight": "model.safetensors",
|
| 224 |
+
"model.layers.17.mlp.gate_proj.biases": "model.safetensors",
|
| 225 |
+
"model.layers.17.mlp.gate_proj.scales": "model.safetensors",
|
| 226 |
+
"model.layers.17.mlp.gate_proj.weight": "model.safetensors",
|
| 227 |
+
"model.layers.17.mlp.up_proj.biases": "model.safetensors",
|
| 228 |
+
"model.layers.17.mlp.up_proj.scales": "model.safetensors",
|
| 229 |
+
"model.layers.17.mlp.up_proj.weight": "model.safetensors",
|
| 230 |
+
"model.layers.17.post_attention_layernorm.weight": "model.safetensors",
|
| 231 |
+
"model.layers.17.self_attn.k_proj.biases": "model.safetensors",
|
| 232 |
+
"model.layers.17.self_attn.k_proj.scales": "model.safetensors",
|
| 233 |
+
"model.layers.17.self_attn.k_proj.weight": "model.safetensors",
|
| 234 |
+
"model.layers.17.self_attn.o_proj.biases": "model.safetensors",
|
| 235 |
+
"model.layers.17.self_attn.o_proj.scales": "model.safetensors",
|
| 236 |
+
"model.layers.17.self_attn.o_proj.weight": "model.safetensors",
|
| 237 |
+
"model.layers.17.self_attn.q_proj.biases": "model.safetensors",
|
| 238 |
+
"model.layers.17.self_attn.q_proj.scales": "model.safetensors",
|
| 239 |
+
"model.layers.17.self_attn.q_proj.weight": "model.safetensors",
|
| 240 |
+
"model.layers.17.self_attn.v_proj.biases": "model.safetensors",
|
| 241 |
+
"model.layers.17.self_attn.v_proj.scales": "model.safetensors",
|
| 242 |
+
"model.layers.17.self_attn.v_proj.weight": "model.safetensors",
|
| 243 |
+
"model.layers.18.input_layernorm.weight": "model.safetensors",
|
| 244 |
+
"model.layers.18.mlp.down_proj.biases": "model.safetensors",
|
| 245 |
+
"model.layers.18.mlp.down_proj.scales": "model.safetensors",
|
| 246 |
+
"model.layers.18.mlp.down_proj.weight": "model.safetensors",
|
| 247 |
+
"model.layers.18.mlp.gate_proj.biases": "model.safetensors",
|
| 248 |
+
"model.layers.18.mlp.gate_proj.scales": "model.safetensors",
|
| 249 |
+
"model.layers.18.mlp.gate_proj.weight": "model.safetensors",
|
| 250 |
+
"model.layers.18.mlp.up_proj.biases": "model.safetensors",
|
| 251 |
+
"model.layers.18.mlp.up_proj.scales": "model.safetensors",
|
| 252 |
+
"model.layers.18.mlp.up_proj.weight": "model.safetensors",
|
| 253 |
+
"model.layers.18.post_attention_layernorm.weight": "model.safetensors",
|
| 254 |
+
"model.layers.18.self_attn.k_proj.biases": "model.safetensors",
|
| 255 |
+
"model.layers.18.self_attn.k_proj.scales": "model.safetensors",
|
| 256 |
+
"model.layers.18.self_attn.k_proj.weight": "model.safetensors",
|
| 257 |
+
"model.layers.18.self_attn.o_proj.biases": "model.safetensors",
|
| 258 |
+
"model.layers.18.self_attn.o_proj.scales": "model.safetensors",
|
| 259 |
+
"model.layers.18.self_attn.o_proj.weight": "model.safetensors",
|
| 260 |
+
"model.layers.18.self_attn.q_proj.biases": "model.safetensors",
|
| 261 |
+
"model.layers.18.self_attn.q_proj.scales": "model.safetensors",
|
| 262 |
+
"model.layers.18.self_attn.q_proj.weight": "model.safetensors",
|
| 263 |
+
"model.layers.18.self_attn.v_proj.biases": "model.safetensors",
|
| 264 |
+
"model.layers.18.self_attn.v_proj.scales": "model.safetensors",
|
| 265 |
+
"model.layers.18.self_attn.v_proj.weight": "model.safetensors",
|
| 266 |
+
"model.layers.19.input_layernorm.weight": "model.safetensors",
|
| 267 |
+
"model.layers.19.mlp.down_proj.biases": "model.safetensors",
|
| 268 |
+
"model.layers.19.mlp.down_proj.scales": "model.safetensors",
|
| 269 |
+
"model.layers.19.mlp.down_proj.weight": "model.safetensors",
|
| 270 |
+
"model.layers.19.mlp.gate_proj.biases": "model.safetensors",
|
| 271 |
+
"model.layers.19.mlp.gate_proj.scales": "model.safetensors",
|
| 272 |
+
"model.layers.19.mlp.gate_proj.weight": "model.safetensors",
|
| 273 |
+
"model.layers.19.mlp.up_proj.biases": "model.safetensors",
|
| 274 |
+
"model.layers.19.mlp.up_proj.scales": "model.safetensors",
|
| 275 |
+
"model.layers.19.mlp.up_proj.weight": "model.safetensors",
|
| 276 |
+
"model.layers.19.post_attention_layernorm.weight": "model.safetensors",
|
| 277 |
+
"model.layers.19.self_attn.k_proj.biases": "model.safetensors",
|
| 278 |
+
"model.layers.19.self_attn.k_proj.scales": "model.safetensors",
|
| 279 |
+
"model.layers.19.self_attn.k_proj.weight": "model.safetensors",
|
| 280 |
+
"model.layers.19.self_attn.o_proj.biases": "model.safetensors",
|
| 281 |
+
"model.layers.19.self_attn.o_proj.scales": "model.safetensors",
|
| 282 |
+
"model.layers.19.self_attn.o_proj.weight": "model.safetensors",
|
| 283 |
+
"model.layers.19.self_attn.q_proj.biases": "model.safetensors",
|
| 284 |
+
"model.layers.19.self_attn.q_proj.scales": "model.safetensors",
|
| 285 |
+
"model.layers.19.self_attn.q_proj.weight": "model.safetensors",
|
| 286 |
+
"model.layers.19.self_attn.v_proj.biases": "model.safetensors",
|
| 287 |
+
"model.layers.19.self_attn.v_proj.scales": "model.safetensors",
|
| 288 |
+
"model.layers.19.self_attn.v_proj.weight": "model.safetensors",
|
| 289 |
+
"model.layers.2.input_layernorm.weight": "model.safetensors",
|
| 290 |
+
"model.layers.2.mlp.down_proj.biases": "model.safetensors",
|
| 291 |
+
"model.layers.2.mlp.down_proj.scales": "model.safetensors",
|
| 292 |
+
"model.layers.2.mlp.down_proj.weight": "model.safetensors",
|
| 293 |
+
"model.layers.2.mlp.gate_proj.biases": "model.safetensors",
|
| 294 |
+
"model.layers.2.mlp.gate_proj.scales": "model.safetensors",
|
| 295 |
+
"model.layers.2.mlp.gate_proj.weight": "model.safetensors",
|
| 296 |
+
"model.layers.2.mlp.up_proj.biases": "model.safetensors",
|
| 297 |
+
"model.layers.2.mlp.up_proj.scales": "model.safetensors",
|
| 298 |
+
"model.layers.2.mlp.up_proj.weight": "model.safetensors",
|
| 299 |
+
"model.layers.2.post_attention_layernorm.weight": "model.safetensors",
|
| 300 |
+
"model.layers.2.self_attn.k_proj.biases": "model.safetensors",
|
| 301 |
+
"model.layers.2.self_attn.k_proj.scales": "model.safetensors",
|
| 302 |
+
"model.layers.2.self_attn.k_proj.weight": "model.safetensors",
|
| 303 |
+
"model.layers.2.self_attn.o_proj.biases": "model.safetensors",
|
| 304 |
+
"model.layers.2.self_attn.o_proj.scales": "model.safetensors",
|
| 305 |
+
"model.layers.2.self_attn.o_proj.weight": "model.safetensors",
|
| 306 |
+
"model.layers.2.self_attn.q_proj.biases": "model.safetensors",
|
| 307 |
+
"model.layers.2.self_attn.q_proj.scales": "model.safetensors",
|
| 308 |
+
"model.layers.2.self_attn.q_proj.weight": "model.safetensors",
|
| 309 |
+
"model.layers.2.self_attn.v_proj.biases": "model.safetensors",
|
| 310 |
+
"model.layers.2.self_attn.v_proj.scales": "model.safetensors",
|
| 311 |
+
"model.layers.2.self_attn.v_proj.weight": "model.safetensors",
|
| 312 |
+
"model.layers.20.input_layernorm.weight": "model.safetensors",
|
| 313 |
+
"model.layers.20.mlp.down_proj.biases": "model.safetensors",
|
| 314 |
+
"model.layers.20.mlp.down_proj.scales": "model.safetensors",
|
| 315 |
+
"model.layers.20.mlp.down_proj.weight": "model.safetensors",
|
| 316 |
+
"model.layers.20.mlp.gate_proj.biases": "model.safetensors",
|
| 317 |
+
"model.layers.20.mlp.gate_proj.scales": "model.safetensors",
|
| 318 |
+
"model.layers.20.mlp.gate_proj.weight": "model.safetensors",
|
| 319 |
+
"model.layers.20.mlp.up_proj.biases": "model.safetensors",
|
| 320 |
+
"model.layers.20.mlp.up_proj.scales": "model.safetensors",
|
| 321 |
+
"model.layers.20.mlp.up_proj.weight": "model.safetensors",
|
| 322 |
+
"model.layers.20.post_attention_layernorm.weight": "model.safetensors",
|
| 323 |
+
"model.layers.20.self_attn.k_proj.biases": "model.safetensors",
|
| 324 |
+
"model.layers.20.self_attn.k_proj.scales": "model.safetensors",
|
| 325 |
+
"model.layers.20.self_attn.k_proj.weight": "model.safetensors",
|
| 326 |
+
"model.layers.20.self_attn.o_proj.biases": "model.safetensors",
|
| 327 |
+
"model.layers.20.self_attn.o_proj.scales": "model.safetensors",
|
| 328 |
+
"model.layers.20.self_attn.o_proj.weight": "model.safetensors",
|
| 329 |
+
"model.layers.20.self_attn.q_proj.biases": "model.safetensors",
|
| 330 |
+
"model.layers.20.self_attn.q_proj.scales": "model.safetensors",
|
| 331 |
+
"model.layers.20.self_attn.q_proj.weight": "model.safetensors",
|
| 332 |
+
"model.layers.20.self_attn.v_proj.biases": "model.safetensors",
|
| 333 |
+
"model.layers.20.self_attn.v_proj.scales": "model.safetensors",
|
| 334 |
+
"model.layers.20.self_attn.v_proj.weight": "model.safetensors",
|
| 335 |
+
"model.layers.21.input_layernorm.weight": "model.safetensors",
|
| 336 |
+
"model.layers.21.mlp.down_proj.biases": "model.safetensors",
|
| 337 |
+
"model.layers.21.mlp.down_proj.scales": "model.safetensors",
|
| 338 |
+
"model.layers.21.mlp.down_proj.weight": "model.safetensors",
|
| 339 |
+
"model.layers.21.mlp.gate_proj.biases": "model.safetensors",
|
| 340 |
+
"model.layers.21.mlp.gate_proj.scales": "model.safetensors",
|
| 341 |
+
"model.layers.21.mlp.gate_proj.weight": "model.safetensors",
|
| 342 |
+
"model.layers.21.mlp.up_proj.biases": "model.safetensors",
|
| 343 |
+
"model.layers.21.mlp.up_proj.scales": "model.safetensors",
|
| 344 |
+
"model.layers.21.mlp.up_proj.weight": "model.safetensors",
|
| 345 |
+
"model.layers.21.post_attention_layernorm.weight": "model.safetensors",
|
| 346 |
+
"model.layers.21.self_attn.k_proj.biases": "model.safetensors",
|
| 347 |
+
"model.layers.21.self_attn.k_proj.scales": "model.safetensors",
|
| 348 |
+
"model.layers.21.self_attn.k_proj.weight": "model.safetensors",
|
| 349 |
+
"model.layers.21.self_attn.o_proj.biases": "model.safetensors",
|
| 350 |
+
"model.layers.21.self_attn.o_proj.scales": "model.safetensors",
|
| 351 |
+
"model.layers.21.self_attn.o_proj.weight": "model.safetensors",
|
| 352 |
+
"model.layers.21.self_attn.q_proj.biases": "model.safetensors",
|
| 353 |
+
"model.layers.21.self_attn.q_proj.scales": "model.safetensors",
|
| 354 |
+
"model.layers.21.self_attn.q_proj.weight": "model.safetensors",
|
| 355 |
+
"model.layers.21.self_attn.v_proj.biases": "model.safetensors",
|
| 356 |
+
"model.layers.21.self_attn.v_proj.scales": "model.safetensors",
|
| 357 |
+
"model.layers.21.self_attn.v_proj.weight": "model.safetensors",
|
| 358 |
+
"model.layers.22.input_layernorm.weight": "model.safetensors",
|
| 359 |
+
"model.layers.22.mlp.down_proj.biases": "model.safetensors",
|
| 360 |
+
"model.layers.22.mlp.down_proj.scales": "model.safetensors",
|
| 361 |
+
"model.layers.22.mlp.down_proj.weight": "model.safetensors",
|
| 362 |
+
"model.layers.22.mlp.gate_proj.biases": "model.safetensors",
|
| 363 |
+
"model.layers.22.mlp.gate_proj.scales": "model.safetensors",
|
| 364 |
+
"model.layers.22.mlp.gate_proj.weight": "model.safetensors",
|
| 365 |
+
"model.layers.22.mlp.up_proj.biases": "model.safetensors",
|
| 366 |
+
"model.layers.22.mlp.up_proj.scales": "model.safetensors",
|
| 367 |
+
"model.layers.22.mlp.up_proj.weight": "model.safetensors",
|
| 368 |
+
"model.layers.22.post_attention_layernorm.weight": "model.safetensors",
|
| 369 |
+
"model.layers.22.self_attn.k_proj.biases": "model.safetensors",
|
| 370 |
+
"model.layers.22.self_attn.k_proj.scales": "model.safetensors",
|
| 371 |
+
"model.layers.22.self_attn.k_proj.weight": "model.safetensors",
|
| 372 |
+
"model.layers.22.self_attn.o_proj.biases": "model.safetensors",
|
| 373 |
+
"model.layers.22.self_attn.o_proj.scales": "model.safetensors",
|
| 374 |
+
"model.layers.22.self_attn.o_proj.weight": "model.safetensors",
|
| 375 |
+
"model.layers.22.self_attn.q_proj.biases": "model.safetensors",
|
| 376 |
+
"model.layers.22.self_attn.q_proj.scales": "model.safetensors",
|
| 377 |
+
"model.layers.22.self_attn.q_proj.weight": "model.safetensors",
|
| 378 |
+
"model.layers.22.self_attn.v_proj.biases": "model.safetensors",
|
| 379 |
+
"model.layers.22.self_attn.v_proj.scales": "model.safetensors",
|
| 380 |
+
"model.layers.22.self_attn.v_proj.weight": "model.safetensors",
|
| 381 |
+
"model.layers.23.input_layernorm.weight": "model.safetensors",
|
| 382 |
+
"model.layers.23.mlp.down_proj.biases": "model.safetensors",
|
| 383 |
+
"model.layers.23.mlp.down_proj.scales": "model.safetensors",
|
| 384 |
+
"model.layers.23.mlp.down_proj.weight": "model.safetensors",
|
| 385 |
+
"model.layers.23.mlp.gate_proj.biases": "model.safetensors",
|
| 386 |
+
"model.layers.23.mlp.gate_proj.scales": "model.safetensors",
|
| 387 |
+
"model.layers.23.mlp.gate_proj.weight": "model.safetensors",
|
| 388 |
+
"model.layers.23.mlp.up_proj.biases": "model.safetensors",
|
| 389 |
+
"model.layers.23.mlp.up_proj.scales": "model.safetensors",
|
| 390 |
+
"model.layers.23.mlp.up_proj.weight": "model.safetensors",
|
| 391 |
+
"model.layers.23.post_attention_layernorm.weight": "model.safetensors",
|
| 392 |
+
"model.layers.23.self_attn.k_proj.biases": "model.safetensors",
|
| 393 |
+
"model.layers.23.self_attn.k_proj.scales": "model.safetensors",
|
| 394 |
+
"model.layers.23.self_attn.k_proj.weight": "model.safetensors",
|
| 395 |
+
"model.layers.23.self_attn.o_proj.biases": "model.safetensors",
|
| 396 |
+
"model.layers.23.self_attn.o_proj.scales": "model.safetensors",
|
| 397 |
+
"model.layers.23.self_attn.o_proj.weight": "model.safetensors",
|
| 398 |
+
"model.layers.23.self_attn.q_proj.biases": "model.safetensors",
|
| 399 |
+
"model.layers.23.self_attn.q_proj.scales": "model.safetensors",
|
| 400 |
+
"model.layers.23.self_attn.q_proj.weight": "model.safetensors",
|
| 401 |
+
"model.layers.23.self_attn.v_proj.biases": "model.safetensors",
|
| 402 |
+
"model.layers.23.self_attn.v_proj.scales": "model.safetensors",
|
| 403 |
+
"model.layers.23.self_attn.v_proj.weight": "model.safetensors",
|
| 404 |
+
"model.layers.24.input_layernorm.weight": "model.safetensors",
|
| 405 |
+
"model.layers.24.mlp.down_proj.biases": "model.safetensors",
|
| 406 |
+
"model.layers.24.mlp.down_proj.scales": "model.safetensors",
|
| 407 |
+
"model.layers.24.mlp.down_proj.weight": "model.safetensors",
|
| 408 |
+
"model.layers.24.mlp.gate_proj.biases": "model.safetensors",
|
| 409 |
+
"model.layers.24.mlp.gate_proj.scales": "model.safetensors",
|
| 410 |
+
"model.layers.24.mlp.gate_proj.weight": "model.safetensors",
|
| 411 |
+
"model.layers.24.mlp.up_proj.biases": "model.safetensors",
|
| 412 |
+
"model.layers.24.mlp.up_proj.scales": "model.safetensors",
|
| 413 |
+
"model.layers.24.mlp.up_proj.weight": "model.safetensors",
|
| 414 |
+
"model.layers.24.post_attention_layernorm.weight": "model.safetensors",
|
| 415 |
+
"model.layers.24.self_attn.k_proj.biases": "model.safetensors",
|
| 416 |
+
"model.layers.24.self_attn.k_proj.scales": "model.safetensors",
|
| 417 |
+
"model.layers.24.self_attn.k_proj.weight": "model.safetensors",
|
| 418 |
+
"model.layers.24.self_attn.o_proj.biases": "model.safetensors",
|
| 419 |
+
"model.layers.24.self_attn.o_proj.scales": "model.safetensors",
|
| 420 |
+
"model.layers.24.self_attn.o_proj.weight": "model.safetensors",
|
| 421 |
+
"model.layers.24.self_attn.q_proj.biases": "model.safetensors",
|
| 422 |
+
"model.layers.24.self_attn.q_proj.scales": "model.safetensors",
|
| 423 |
+
"model.layers.24.self_attn.q_proj.weight": "model.safetensors",
|
| 424 |
+
"model.layers.24.self_attn.v_proj.biases": "model.safetensors",
|
| 425 |
+
"model.layers.24.self_attn.v_proj.scales": "model.safetensors",
|
| 426 |
+
"model.layers.24.self_attn.v_proj.weight": "model.safetensors",
|
| 427 |
+
"model.layers.25.input_layernorm.weight": "model.safetensors",
|
| 428 |
+
"model.layers.25.mlp.down_proj.biases": "model.safetensors",
|
| 429 |
+
"model.layers.25.mlp.down_proj.scales": "model.safetensors",
|
| 430 |
+
"model.layers.25.mlp.down_proj.weight": "model.safetensors",
|
| 431 |
+
"model.layers.25.mlp.gate_proj.biases": "model.safetensors",
|
| 432 |
+
"model.layers.25.mlp.gate_proj.scales": "model.safetensors",
|
| 433 |
+
"model.layers.25.mlp.gate_proj.weight": "model.safetensors",
|
| 434 |
+
"model.layers.25.mlp.up_proj.biases": "model.safetensors",
|
| 435 |
+
"model.layers.25.mlp.up_proj.scales": "model.safetensors",
|
| 436 |
+
"model.layers.25.mlp.up_proj.weight": "model.safetensors",
|
| 437 |
+
"model.layers.25.post_attention_layernorm.weight": "model.safetensors",
|
| 438 |
+
"model.layers.25.self_attn.k_proj.biases": "model.safetensors",
|
| 439 |
+
"model.layers.25.self_attn.k_proj.scales": "model.safetensors",
|
| 440 |
+
"model.layers.25.self_attn.k_proj.weight": "model.safetensors",
|
| 441 |
+
"model.layers.25.self_attn.o_proj.biases": "model.safetensors",
|
| 442 |
+
"model.layers.25.self_attn.o_proj.scales": "model.safetensors",
|
| 443 |
+
"model.layers.25.self_attn.o_proj.weight": "model.safetensors",
|
| 444 |
+
"model.layers.25.self_attn.q_proj.biases": "model.safetensors",
|
| 445 |
+
"model.layers.25.self_attn.q_proj.scales": "model.safetensors",
|
| 446 |
+
"model.layers.25.self_attn.q_proj.weight": "model.safetensors",
|
| 447 |
+
"model.layers.25.self_attn.v_proj.biases": "model.safetensors",
|
| 448 |
+
"model.layers.25.self_attn.v_proj.scales": "model.safetensors",
|
| 449 |
+
"model.layers.25.self_attn.v_proj.weight": "model.safetensors",
|
| 450 |
+
"model.layers.26.input_layernorm.weight": "model.safetensors",
|
| 451 |
+
"model.layers.26.mlp.down_proj.biases": "model.safetensors",
|
| 452 |
+
"model.layers.26.mlp.down_proj.scales": "model.safetensors",
|
| 453 |
+
"model.layers.26.mlp.down_proj.weight": "model.safetensors",
|
| 454 |
+
"model.layers.26.mlp.gate_proj.biases": "model.safetensors",
|
| 455 |
+
"model.layers.26.mlp.gate_proj.scales": "model.safetensors",
|
| 456 |
+
"model.layers.26.mlp.gate_proj.weight": "model.safetensors",
|
| 457 |
+
"model.layers.26.mlp.up_proj.biases": "model.safetensors",
|
| 458 |
+
"model.layers.26.mlp.up_proj.scales": "model.safetensors",
|
| 459 |
+
"model.layers.26.mlp.up_proj.weight": "model.safetensors",
|
| 460 |
+
"model.layers.26.post_attention_layernorm.weight": "model.safetensors",
|
| 461 |
+
"model.layers.26.self_attn.k_proj.biases": "model.safetensors",
|
| 462 |
+
"model.layers.26.self_attn.k_proj.scales": "model.safetensors",
|
| 463 |
+
"model.layers.26.self_attn.k_proj.weight": "model.safetensors",
|
| 464 |
+
"model.layers.26.self_attn.o_proj.biases": "model.safetensors",
|
| 465 |
+
"model.layers.26.self_attn.o_proj.scales": "model.safetensors",
|
| 466 |
+
"model.layers.26.self_attn.o_proj.weight": "model.safetensors",
|
| 467 |
+
"model.layers.26.self_attn.q_proj.biases": "model.safetensors",
|
| 468 |
+
"model.layers.26.self_attn.q_proj.scales": "model.safetensors",
|
| 469 |
+
"model.layers.26.self_attn.q_proj.weight": "model.safetensors",
|
| 470 |
+
"model.layers.26.self_attn.v_proj.biases": "model.safetensors",
|
| 471 |
+
"model.layers.26.self_attn.v_proj.scales": "model.safetensors",
|
| 472 |
+
"model.layers.26.self_attn.v_proj.weight": "model.safetensors",
|
| 473 |
+
"model.layers.27.input_layernorm.weight": "model.safetensors",
|
| 474 |
+
"model.layers.27.mlp.down_proj.biases": "model.safetensors",
|
| 475 |
+
"model.layers.27.mlp.down_proj.scales": "model.safetensors",
|
| 476 |
+
"model.layers.27.mlp.down_proj.weight": "model.safetensors",
|
| 477 |
+
"model.layers.27.mlp.gate_proj.biases": "model.safetensors",
|
| 478 |
+
"model.layers.27.mlp.gate_proj.scales": "model.safetensors",
|
| 479 |
+
"model.layers.27.mlp.gate_proj.weight": "model.safetensors",
|
| 480 |
+
"model.layers.27.mlp.up_proj.biases": "model.safetensors",
|
| 481 |
+
"model.layers.27.mlp.up_proj.scales": "model.safetensors",
|
| 482 |
+
"model.layers.27.mlp.up_proj.weight": "model.safetensors",
|
| 483 |
+
"model.layers.27.post_attention_layernorm.weight": "model.safetensors",
|
| 484 |
+
"model.layers.27.self_attn.k_proj.biases": "model.safetensors",
|
| 485 |
+
"model.layers.27.self_attn.k_proj.scales": "model.safetensors",
|
| 486 |
+
"model.layers.27.self_attn.k_proj.weight": "model.safetensors",
|
| 487 |
+
"model.layers.27.self_attn.o_proj.biases": "model.safetensors",
|
| 488 |
+
"model.layers.27.self_attn.o_proj.scales": "model.safetensors",
|
| 489 |
+
"model.layers.27.self_attn.o_proj.weight": "model.safetensors",
|
| 490 |
+
"model.layers.27.self_attn.q_proj.biases": "model.safetensors",
|
| 491 |
+
"model.layers.27.self_attn.q_proj.scales": "model.safetensors",
|
| 492 |
+
"model.layers.27.self_attn.q_proj.weight": "model.safetensors",
|
| 493 |
+
"model.layers.27.self_attn.v_proj.biases": "model.safetensors",
|
| 494 |
+
"model.layers.27.self_attn.v_proj.scales": "model.safetensors",
|
| 495 |
+
"model.layers.27.self_attn.v_proj.weight": "model.safetensors",
|
| 496 |
+
"model.layers.28.input_layernorm.weight": "model.safetensors",
|
| 497 |
+
"model.layers.28.mlp.down_proj.biases": "model.safetensors",
|
| 498 |
+
"model.layers.28.mlp.down_proj.scales": "model.safetensors",
|
| 499 |
+
"model.layers.28.mlp.down_proj.weight": "model.safetensors",
|
| 500 |
+
"model.layers.28.mlp.gate_proj.biases": "model.safetensors",
|
| 501 |
+
"model.layers.28.mlp.gate_proj.scales": "model.safetensors",
|
| 502 |
+
"model.layers.28.mlp.gate_proj.weight": "model.safetensors",
|
| 503 |
+
"model.layers.28.mlp.up_proj.biases": "model.safetensors",
|
| 504 |
+
"model.layers.28.mlp.up_proj.scales": "model.safetensors",
|
| 505 |
+
"model.layers.28.mlp.up_proj.weight": "model.safetensors",
|
| 506 |
+
"model.layers.28.post_attention_layernorm.weight": "model.safetensors",
|
| 507 |
+
"model.layers.28.self_attn.k_proj.biases": "model.safetensors",
|
| 508 |
+
"model.layers.28.self_attn.k_proj.scales": "model.safetensors",
|
| 509 |
+
"model.layers.28.self_attn.k_proj.weight": "model.safetensors",
|
| 510 |
+
"model.layers.28.self_attn.o_proj.biases": "model.safetensors",
|
| 511 |
+
"model.layers.28.self_attn.o_proj.scales": "model.safetensors",
|
| 512 |
+
"model.layers.28.self_attn.o_proj.weight": "model.safetensors",
|
| 513 |
+
"model.layers.28.self_attn.q_proj.biases": "model.safetensors",
|
| 514 |
+
"model.layers.28.self_attn.q_proj.scales": "model.safetensors",
|
| 515 |
+
"model.layers.28.self_attn.q_proj.weight": "model.safetensors",
|
| 516 |
+
"model.layers.28.self_attn.v_proj.biases": "model.safetensors",
|
| 517 |
+
"model.layers.28.self_attn.v_proj.scales": "model.safetensors",
|
| 518 |
+
"model.layers.28.self_attn.v_proj.weight": "model.safetensors",
|
| 519 |
+
"model.layers.29.input_layernorm.weight": "model.safetensors",
|
| 520 |
+
"model.layers.29.mlp.down_proj.biases": "model.safetensors",
|
| 521 |
+
"model.layers.29.mlp.down_proj.scales": "model.safetensors",
|
| 522 |
+
"model.layers.29.mlp.down_proj.weight": "model.safetensors",
|
| 523 |
+
"model.layers.29.mlp.gate_proj.biases": "model.safetensors",
|
| 524 |
+
"model.layers.29.mlp.gate_proj.scales": "model.safetensors",
|
| 525 |
+
"model.layers.29.mlp.gate_proj.weight": "model.safetensors",
|
| 526 |
+
"model.layers.29.mlp.up_proj.biases": "model.safetensors",
|
| 527 |
+
"model.layers.29.mlp.up_proj.scales": "model.safetensors",
|
| 528 |
+
"model.layers.29.mlp.up_proj.weight": "model.safetensors",
|
| 529 |
+
"model.layers.29.post_attention_layernorm.weight": "model.safetensors",
|
| 530 |
+
"model.layers.29.self_attn.k_proj.biases": "model.safetensors",
|
| 531 |
+
"model.layers.29.self_attn.k_proj.scales": "model.safetensors",
|
| 532 |
+
"model.layers.29.self_attn.k_proj.weight": "model.safetensors",
|
| 533 |
+
"model.layers.29.self_attn.o_proj.biases": "model.safetensors",
|
| 534 |
+
"model.layers.29.self_attn.o_proj.scales": "model.safetensors",
|
| 535 |
+
"model.layers.29.self_attn.o_proj.weight": "model.safetensors",
|
| 536 |
+
"model.layers.29.self_attn.q_proj.biases": "model.safetensors",
|
| 537 |
+
"model.layers.29.self_attn.q_proj.scales": "model.safetensors",
|
| 538 |
+
"model.layers.29.self_attn.q_proj.weight": "model.safetensors",
|
| 539 |
+
"model.layers.29.self_attn.v_proj.biases": "model.safetensors",
|
| 540 |
+
"model.layers.29.self_attn.v_proj.scales": "model.safetensors",
|
| 541 |
+
"model.layers.29.self_attn.v_proj.weight": "model.safetensors",
|
| 542 |
+
"model.layers.3.input_layernorm.weight": "model.safetensors",
|
| 543 |
+
"model.layers.3.mlp.down_proj.biases": "model.safetensors",
|
| 544 |
+
"model.layers.3.mlp.down_proj.scales": "model.safetensors",
|
| 545 |
+
"model.layers.3.mlp.down_proj.weight": "model.safetensors",
|
| 546 |
+
"model.layers.3.mlp.gate_proj.biases": "model.safetensors",
|
| 547 |
+
"model.layers.3.mlp.gate_proj.scales": "model.safetensors",
|
| 548 |
+
"model.layers.3.mlp.gate_proj.weight": "model.safetensors",
|
| 549 |
+
"model.layers.3.mlp.up_proj.biases": "model.safetensors",
|
| 550 |
+
"model.layers.3.mlp.up_proj.scales": "model.safetensors",
|
| 551 |
+
"model.layers.3.mlp.up_proj.weight": "model.safetensors",
|
| 552 |
+
"model.layers.3.post_attention_layernorm.weight": "model.safetensors",
|
| 553 |
+
"model.layers.3.self_attn.k_proj.biases": "model.safetensors",
|
| 554 |
+
"model.layers.3.self_attn.k_proj.scales": "model.safetensors",
|
| 555 |
+
"model.layers.3.self_attn.k_proj.weight": "model.safetensors",
|
| 556 |
+
"model.layers.3.self_attn.o_proj.biases": "model.safetensors",
|
| 557 |
+
"model.layers.3.self_attn.o_proj.scales": "model.safetensors",
|
| 558 |
+
"model.layers.3.self_attn.o_proj.weight": "model.safetensors",
|
| 559 |
+
"model.layers.3.self_attn.q_proj.biases": "model.safetensors",
|
| 560 |
+
"model.layers.3.self_attn.q_proj.scales": "model.safetensors",
|
| 561 |
+
"model.layers.3.self_attn.q_proj.weight": "model.safetensors",
|
| 562 |
+
"model.layers.3.self_attn.v_proj.biases": "model.safetensors",
|
| 563 |
+
"model.layers.3.self_attn.v_proj.scales": "model.safetensors",
|
| 564 |
+
"model.layers.3.self_attn.v_proj.weight": "model.safetensors",
|
| 565 |
+
"model.layers.30.input_layernorm.weight": "model.safetensors",
|
| 566 |
+
"model.layers.30.mlp.down_proj.biases": "model.safetensors",
|
| 567 |
+
"model.layers.30.mlp.down_proj.scales": "model.safetensors",
|
| 568 |
+
"model.layers.30.mlp.down_proj.weight": "model.safetensors",
|
| 569 |
+
"model.layers.30.mlp.gate_proj.biases": "model.safetensors",
|
| 570 |
+
"model.layers.30.mlp.gate_proj.scales": "model.safetensors",
|
| 571 |
+
"model.layers.30.mlp.gate_proj.weight": "model.safetensors",
|
| 572 |
+
"model.layers.30.mlp.up_proj.biases": "model.safetensors",
|
| 573 |
+
"model.layers.30.mlp.up_proj.scales": "model.safetensors",
|
| 574 |
+
"model.layers.30.mlp.up_proj.weight": "model.safetensors",
|
| 575 |
+
"model.layers.30.post_attention_layernorm.weight": "model.safetensors",
|
| 576 |
+
"model.layers.30.self_attn.k_proj.biases": "model.safetensors",
|
| 577 |
+
"model.layers.30.self_attn.k_proj.scales": "model.safetensors",
|
| 578 |
+
"model.layers.30.self_attn.k_proj.weight": "model.safetensors",
|
| 579 |
+
"model.layers.30.self_attn.o_proj.biases": "model.safetensors",
|
| 580 |
+
"model.layers.30.self_attn.o_proj.scales": "model.safetensors",
|
| 581 |
+
"model.layers.30.self_attn.o_proj.weight": "model.safetensors",
|
| 582 |
+
"model.layers.30.self_attn.q_proj.biases": "model.safetensors",
|
| 583 |
+
"model.layers.30.self_attn.q_proj.scales": "model.safetensors",
|
| 584 |
+
"model.layers.30.self_attn.q_proj.weight": "model.safetensors",
|
| 585 |
+
"model.layers.30.self_attn.v_proj.biases": "model.safetensors",
|
| 586 |
+
"model.layers.30.self_attn.v_proj.scales": "model.safetensors",
|
| 587 |
+
"model.layers.30.self_attn.v_proj.weight": "model.safetensors",
|
| 588 |
+
"model.layers.31.input_layernorm.weight": "model.safetensors",
|
| 589 |
+
"model.layers.31.mlp.down_proj.biases": "model.safetensors",
|
| 590 |
+
"model.layers.31.mlp.down_proj.scales": "model.safetensors",
|
| 591 |
+
"model.layers.31.mlp.down_proj.weight": "model.safetensors",
|
| 592 |
+
"model.layers.31.mlp.gate_proj.biases": "model.safetensors",
|
| 593 |
+
"model.layers.31.mlp.gate_proj.scales": "model.safetensors",
|
| 594 |
+
"model.layers.31.mlp.gate_proj.weight": "model.safetensors",
|
| 595 |
+
"model.layers.31.mlp.up_proj.biases": "model.safetensors",
|
| 596 |
+
"model.layers.31.mlp.up_proj.scales": "model.safetensors",
|
| 597 |
+
"model.layers.31.mlp.up_proj.weight": "model.safetensors",
|
| 598 |
+
"model.layers.31.post_attention_layernorm.weight": "model.safetensors",
|
| 599 |
+
"model.layers.31.self_attn.k_proj.biases": "model.safetensors",
|
| 600 |
+
"model.layers.31.self_attn.k_proj.scales": "model.safetensors",
|
| 601 |
+
"model.layers.31.self_attn.k_proj.weight": "model.safetensors",
|
| 602 |
+
"model.layers.31.self_attn.o_proj.biases": "model.safetensors",
|
| 603 |
+
"model.layers.31.self_attn.o_proj.scales": "model.safetensors",
|
| 604 |
+
"model.layers.31.self_attn.o_proj.weight": "model.safetensors",
|
| 605 |
+
"model.layers.31.self_attn.q_proj.biases": "model.safetensors",
|
| 606 |
+
"model.layers.31.self_attn.q_proj.scales": "model.safetensors",
|
| 607 |
+
"model.layers.31.self_attn.q_proj.weight": "model.safetensors",
|
| 608 |
+
"model.layers.31.self_attn.v_proj.biases": "model.safetensors",
|
| 609 |
+
"model.layers.31.self_attn.v_proj.scales": "model.safetensors",
|
| 610 |
+
"model.layers.31.self_attn.v_proj.weight": "model.safetensors",
|
| 611 |
+
"model.layers.32.input_layernorm.weight": "model.safetensors",
|
| 612 |
+
"model.layers.32.mlp.down_proj.biases": "model.safetensors",
|
| 613 |
+
"model.layers.32.mlp.down_proj.scales": "model.safetensors",
|
| 614 |
+
"model.layers.32.mlp.down_proj.weight": "model.safetensors",
|
| 615 |
+
"model.layers.32.mlp.gate_proj.biases": "model.safetensors",
|
| 616 |
+
"model.layers.32.mlp.gate_proj.scales": "model.safetensors",
|
| 617 |
+
"model.layers.32.mlp.gate_proj.weight": "model.safetensors",
|
| 618 |
+
"model.layers.32.mlp.up_proj.biases": "model.safetensors",
|
| 619 |
+
"model.layers.32.mlp.up_proj.scales": "model.safetensors",
|
| 620 |
+
"model.layers.32.mlp.up_proj.weight": "model.safetensors",
|
| 621 |
+
"model.layers.32.post_attention_layernorm.weight": "model.safetensors",
|
| 622 |
+
"model.layers.32.self_attn.k_proj.biases": "model.safetensors",
|
| 623 |
+
"model.layers.32.self_attn.k_proj.scales": "model.safetensors",
|
| 624 |
+
"model.layers.32.self_attn.k_proj.weight": "model.safetensors",
|
| 625 |
+
"model.layers.32.self_attn.o_proj.biases": "model.safetensors",
|
| 626 |
+
"model.layers.32.self_attn.o_proj.scales": "model.safetensors",
|
| 627 |
+
"model.layers.32.self_attn.o_proj.weight": "model.safetensors",
|
| 628 |
+
"model.layers.32.self_attn.q_proj.biases": "model.safetensors",
|
| 629 |
+
"model.layers.32.self_attn.q_proj.scales": "model.safetensors",
|
| 630 |
+
"model.layers.32.self_attn.q_proj.weight": "model.safetensors",
|
| 631 |
+
"model.layers.32.self_attn.v_proj.biases": "model.safetensors",
|
| 632 |
+
"model.layers.32.self_attn.v_proj.scales": "model.safetensors",
|
| 633 |
+
"model.layers.32.self_attn.v_proj.weight": "model.safetensors",
|
| 634 |
+
"model.layers.33.input_layernorm.weight": "model.safetensors",
|
| 635 |
+
"model.layers.33.mlp.down_proj.biases": "model.safetensors",
|
| 636 |
+
"model.layers.33.mlp.down_proj.scales": "model.safetensors",
|
| 637 |
+
"model.layers.33.mlp.down_proj.weight": "model.safetensors",
|
| 638 |
+
"model.layers.33.mlp.gate_proj.biases": "model.safetensors",
|
| 639 |
+
"model.layers.33.mlp.gate_proj.scales": "model.safetensors",
|
| 640 |
+
"model.layers.33.mlp.gate_proj.weight": "model.safetensors",
|
| 641 |
+
"model.layers.33.mlp.up_proj.biases": "model.safetensors",
|
| 642 |
+
"model.layers.33.mlp.up_proj.scales": "model.safetensors",
|
| 643 |
+
"model.layers.33.mlp.up_proj.weight": "model.safetensors",
|
| 644 |
+
"model.layers.33.post_attention_layernorm.weight": "model.safetensors",
|
| 645 |
+
"model.layers.33.self_attn.k_proj.biases": "model.safetensors",
|
| 646 |
+
"model.layers.33.self_attn.k_proj.scales": "model.safetensors",
|
| 647 |
+
"model.layers.33.self_attn.k_proj.weight": "model.safetensors",
|
| 648 |
+
"model.layers.33.self_attn.o_proj.biases": "model.safetensors",
|
| 649 |
+
"model.layers.33.self_attn.o_proj.scales": "model.safetensors",
|
| 650 |
+
"model.layers.33.self_attn.o_proj.weight": "model.safetensors",
|
| 651 |
+
"model.layers.33.self_attn.q_proj.biases": "model.safetensors",
|
| 652 |
+
"model.layers.33.self_attn.q_proj.scales": "model.safetensors",
|
| 653 |
+
"model.layers.33.self_attn.q_proj.weight": "model.safetensors",
|
| 654 |
+
"model.layers.33.self_attn.v_proj.biases": "model.safetensors",
|
| 655 |
+
"model.layers.33.self_attn.v_proj.scales": "model.safetensors",
|
| 656 |
+
"model.layers.33.self_attn.v_proj.weight": "model.safetensors",
|
| 657 |
+
"model.layers.34.input_layernorm.weight": "model.safetensors",
|
| 658 |
+
"model.layers.34.mlp.down_proj.biases": "model.safetensors",
|
| 659 |
+
"model.layers.34.mlp.down_proj.scales": "model.safetensors",
|
| 660 |
+
"model.layers.34.mlp.down_proj.weight": "model.safetensors",
|
| 661 |
+
"model.layers.34.mlp.gate_proj.biases": "model.safetensors",
|
| 662 |
+
"model.layers.34.mlp.gate_proj.scales": "model.safetensors",
|
| 663 |
+
"model.layers.34.mlp.gate_proj.weight": "model.safetensors",
|
| 664 |
+
"model.layers.34.mlp.up_proj.biases": "model.safetensors",
|
| 665 |
+
"model.layers.34.mlp.up_proj.scales": "model.safetensors",
|
| 666 |
+
"model.layers.34.mlp.up_proj.weight": "model.safetensors",
|
| 667 |
+
"model.layers.34.post_attention_layernorm.weight": "model.safetensors",
|
| 668 |
+
"model.layers.34.self_attn.k_proj.biases": "model.safetensors",
|
| 669 |
+
"model.layers.34.self_attn.k_proj.scales": "model.safetensors",
|
| 670 |
+
"model.layers.34.self_attn.k_proj.weight": "model.safetensors",
|
| 671 |
+
"model.layers.34.self_attn.o_proj.biases": "model.safetensors",
|
| 672 |
+
"model.layers.34.self_attn.o_proj.scales": "model.safetensors",
|
| 673 |
+
"model.layers.34.self_attn.o_proj.weight": "model.safetensors",
|
| 674 |
+
"model.layers.34.self_attn.q_proj.biases": "model.safetensors",
|
| 675 |
+
"model.layers.34.self_attn.q_proj.scales": "model.safetensors",
|
| 676 |
+
"model.layers.34.self_attn.q_proj.weight": "model.safetensors",
|
| 677 |
+
"model.layers.34.self_attn.v_proj.biases": "model.safetensors",
|
| 678 |
+
"model.layers.34.self_attn.v_proj.scales": "model.safetensors",
|
| 679 |
+
"model.layers.34.self_attn.v_proj.weight": "model.safetensors",
|
| 680 |
+
"model.layers.35.input_layernorm.weight": "model.safetensors",
|
| 681 |
+
"model.layers.35.mlp.down_proj.biases": "model.safetensors",
|
| 682 |
+
"model.layers.35.mlp.down_proj.scales": "model.safetensors",
|
| 683 |
+
"model.layers.35.mlp.down_proj.weight": "model.safetensors",
|
| 684 |
+
"model.layers.35.mlp.gate_proj.biases": "model.safetensors",
|
| 685 |
+
"model.layers.35.mlp.gate_proj.scales": "model.safetensors",
|
| 686 |
+
"model.layers.35.mlp.gate_proj.weight": "model.safetensors",
|
| 687 |
+
"model.layers.35.mlp.up_proj.biases": "model.safetensors",
|
| 688 |
+
"model.layers.35.mlp.up_proj.scales": "model.safetensors",
|
| 689 |
+
"model.layers.35.mlp.up_proj.weight": "model.safetensors",
|
| 690 |
+
"model.layers.35.post_attention_layernorm.weight": "model.safetensors",
|
| 691 |
+
"model.layers.35.self_attn.k_proj.biases": "model.safetensors",
|
| 692 |
+
"model.layers.35.self_attn.k_proj.scales": "model.safetensors",
|
| 693 |
+
"model.layers.35.self_attn.k_proj.weight": "model.safetensors",
|
| 694 |
+
"model.layers.35.self_attn.o_proj.biases": "model.safetensors",
|
| 695 |
+
"model.layers.35.self_attn.o_proj.scales": "model.safetensors",
|
| 696 |
+
"model.layers.35.self_attn.o_proj.weight": "model.safetensors",
|
| 697 |
+
"model.layers.35.self_attn.q_proj.biases": "model.safetensors",
|
| 698 |
+
"model.layers.35.self_attn.q_proj.scales": "model.safetensors",
|
| 699 |
+
"model.layers.35.self_attn.q_proj.weight": "model.safetensors",
|
| 700 |
+
"model.layers.35.self_attn.v_proj.biases": "model.safetensors",
|
| 701 |
+
"model.layers.35.self_attn.v_proj.scales": "model.safetensors",
|
| 702 |
+
"model.layers.35.self_attn.v_proj.weight": "model.safetensors",
|
| 703 |
+
"model.layers.4.input_layernorm.weight": "model.safetensors",
|
| 704 |
+
"model.layers.4.mlp.down_proj.biases": "model.safetensors",
|
| 705 |
+
"model.layers.4.mlp.down_proj.scales": "model.safetensors",
|
| 706 |
+
"model.layers.4.mlp.down_proj.weight": "model.safetensors",
|
| 707 |
+
"model.layers.4.mlp.gate_proj.biases": "model.safetensors",
|
| 708 |
+
"model.layers.4.mlp.gate_proj.scales": "model.safetensors",
|
| 709 |
+
"model.layers.4.mlp.gate_proj.weight": "model.safetensors",
|
| 710 |
+
"model.layers.4.mlp.up_proj.biases": "model.safetensors",
|
| 711 |
+
"model.layers.4.mlp.up_proj.scales": "model.safetensors",
|
| 712 |
+
"model.layers.4.mlp.up_proj.weight": "model.safetensors",
|
| 713 |
+
"model.layers.4.post_attention_layernorm.weight": "model.safetensors",
|
| 714 |
+
"model.layers.4.self_attn.k_proj.biases": "model.safetensors",
|
| 715 |
+
"model.layers.4.self_attn.k_proj.scales": "model.safetensors",
|
| 716 |
+
"model.layers.4.self_attn.k_proj.weight": "model.safetensors",
|
| 717 |
+
"model.layers.4.self_attn.o_proj.biases": "model.safetensors",
|
| 718 |
+
"model.layers.4.self_attn.o_proj.scales": "model.safetensors",
|
| 719 |
+
"model.layers.4.self_attn.o_proj.weight": "model.safetensors",
|
| 720 |
+
"model.layers.4.self_attn.q_proj.biases": "model.safetensors",
|
| 721 |
+
"model.layers.4.self_attn.q_proj.scales": "model.safetensors",
|
| 722 |
+
"model.layers.4.self_attn.q_proj.weight": "model.safetensors",
|
| 723 |
+
"model.layers.4.self_attn.v_proj.biases": "model.safetensors",
|
| 724 |
+
"model.layers.4.self_attn.v_proj.scales": "model.safetensors",
|
| 725 |
+
"model.layers.4.self_attn.v_proj.weight": "model.safetensors",
|
| 726 |
+
"model.layers.5.input_layernorm.weight": "model.safetensors",
|
| 727 |
+
"model.layers.5.mlp.down_proj.biases": "model.safetensors",
|
| 728 |
+
"model.layers.5.mlp.down_proj.scales": "model.safetensors",
|
| 729 |
+
"model.layers.5.mlp.down_proj.weight": "model.safetensors",
|
| 730 |
+
"model.layers.5.mlp.gate_proj.biases": "model.safetensors",
|
| 731 |
+
"model.layers.5.mlp.gate_proj.scales": "model.safetensors",
|
| 732 |
+
"model.layers.5.mlp.gate_proj.weight": "model.safetensors",
|
| 733 |
+
"model.layers.5.mlp.up_proj.biases": "model.safetensors",
|
| 734 |
+
"model.layers.5.mlp.up_proj.scales": "model.safetensors",
|
| 735 |
+
"model.layers.5.mlp.up_proj.weight": "model.safetensors",
|
| 736 |
+
"model.layers.5.post_attention_layernorm.weight": "model.safetensors",
|
| 737 |
+
"model.layers.5.self_attn.k_proj.biases": "model.safetensors",
|
| 738 |
+
"model.layers.5.self_attn.k_proj.scales": "model.safetensors",
|
| 739 |
+
"model.layers.5.self_attn.k_proj.weight": "model.safetensors",
|
| 740 |
+
"model.layers.5.self_attn.o_proj.biases": "model.safetensors",
|
| 741 |
+
"model.layers.5.self_attn.o_proj.scales": "model.safetensors",
|
| 742 |
+
"model.layers.5.self_attn.o_proj.weight": "model.safetensors",
|
| 743 |
+
"model.layers.5.self_attn.q_proj.biases": "model.safetensors",
|
| 744 |
+
"model.layers.5.self_attn.q_proj.scales": "model.safetensors",
|
| 745 |
+
"model.layers.5.self_attn.q_proj.weight": "model.safetensors",
|
| 746 |
+
"model.layers.5.self_attn.v_proj.biases": "model.safetensors",
|
| 747 |
+
"model.layers.5.self_attn.v_proj.scales": "model.safetensors",
|
| 748 |
+
"model.layers.5.self_attn.v_proj.weight": "model.safetensors",
|
| 749 |
+
"model.layers.6.input_layernorm.weight": "model.safetensors",
|
| 750 |
+
"model.layers.6.mlp.down_proj.biases": "model.safetensors",
|
| 751 |
+
"model.layers.6.mlp.down_proj.scales": "model.safetensors",
|
| 752 |
+
"model.layers.6.mlp.down_proj.weight": "model.safetensors",
|
| 753 |
+
"model.layers.6.mlp.gate_proj.biases": "model.safetensors",
|
| 754 |
+
"model.layers.6.mlp.gate_proj.scales": "model.safetensors",
|
| 755 |
+
"model.layers.6.mlp.gate_proj.weight": "model.safetensors",
|
| 756 |
+
"model.layers.6.mlp.up_proj.biases": "model.safetensors",
|
| 757 |
+
"model.layers.6.mlp.up_proj.scales": "model.safetensors",
|
| 758 |
+
"model.layers.6.mlp.up_proj.weight": "model.safetensors",
|
| 759 |
+
"model.layers.6.post_attention_layernorm.weight": "model.safetensors",
|
| 760 |
+
"model.layers.6.self_attn.k_proj.biases": "model.safetensors",
|
| 761 |
+
"model.layers.6.self_attn.k_proj.scales": "model.safetensors",
|
| 762 |
+
"model.layers.6.self_attn.k_proj.weight": "model.safetensors",
|
| 763 |
+
"model.layers.6.self_attn.o_proj.biases": "model.safetensors",
|
| 764 |
+
"model.layers.6.self_attn.o_proj.scales": "model.safetensors",
|
| 765 |
+
"model.layers.6.self_attn.o_proj.weight": "model.safetensors",
|
| 766 |
+
"model.layers.6.self_attn.q_proj.biases": "model.safetensors",
|
| 767 |
+
"model.layers.6.self_attn.q_proj.scales": "model.safetensors",
|
| 768 |
+
"model.layers.6.self_attn.q_proj.weight": "model.safetensors",
|
| 769 |
+
"model.layers.6.self_attn.v_proj.biases": "model.safetensors",
|
| 770 |
+
"model.layers.6.self_attn.v_proj.scales": "model.safetensors",
|
| 771 |
+
"model.layers.6.self_attn.v_proj.weight": "model.safetensors",
|
| 772 |
+
"model.layers.7.input_layernorm.weight": "model.safetensors",
|
| 773 |
+
"model.layers.7.mlp.down_proj.biases": "model.safetensors",
|
| 774 |
+
"model.layers.7.mlp.down_proj.scales": "model.safetensors",
|
| 775 |
+
"model.layers.7.mlp.down_proj.weight": "model.safetensors",
|
| 776 |
+
"model.layers.7.mlp.gate_proj.biases": "model.safetensors",
|
| 777 |
+
"model.layers.7.mlp.gate_proj.scales": "model.safetensors",
|
| 778 |
+
"model.layers.7.mlp.gate_proj.weight": "model.safetensors",
|
| 779 |
+
"model.layers.7.mlp.up_proj.biases": "model.safetensors",
|
| 780 |
+
"model.layers.7.mlp.up_proj.scales": "model.safetensors",
|
| 781 |
+
"model.layers.7.mlp.up_proj.weight": "model.safetensors",
|
| 782 |
+
"model.layers.7.post_attention_layernorm.weight": "model.safetensors",
|
| 783 |
+
"model.layers.7.self_attn.k_proj.biases": "model.safetensors",
|
| 784 |
+
"model.layers.7.self_attn.k_proj.scales": "model.safetensors",
|
| 785 |
+
"model.layers.7.self_attn.k_proj.weight": "model.safetensors",
|
| 786 |
+
"model.layers.7.self_attn.o_proj.biases": "model.safetensors",
|
| 787 |
+
"model.layers.7.self_attn.o_proj.scales": "model.safetensors",
|
| 788 |
+
"model.layers.7.self_attn.o_proj.weight": "model.safetensors",
|
| 789 |
+
"model.layers.7.self_attn.q_proj.biases": "model.safetensors",
|
| 790 |
+
"model.layers.7.self_attn.q_proj.scales": "model.safetensors",
|
| 791 |
+
"model.layers.7.self_attn.q_proj.weight": "model.safetensors",
|
| 792 |
+
"model.layers.7.self_attn.v_proj.biases": "model.safetensors",
|
| 793 |
+
"model.layers.7.self_attn.v_proj.scales": "model.safetensors",
|
| 794 |
+
"model.layers.7.self_attn.v_proj.weight": "model.safetensors",
|
| 795 |
+
"model.layers.8.input_layernorm.weight": "model.safetensors",
|
| 796 |
+
"model.layers.8.mlp.down_proj.biases": "model.safetensors",
|
| 797 |
+
"model.layers.8.mlp.down_proj.scales": "model.safetensors",
|
| 798 |
+
"model.layers.8.mlp.down_proj.weight": "model.safetensors",
|
| 799 |
+
"model.layers.8.mlp.gate_proj.biases": "model.safetensors",
|
| 800 |
+
"model.layers.8.mlp.gate_proj.scales": "model.safetensors",
|
| 801 |
+
"model.layers.8.mlp.gate_proj.weight": "model.safetensors",
|
| 802 |
+
"model.layers.8.mlp.up_proj.biases": "model.safetensors",
|
| 803 |
+
"model.layers.8.mlp.up_proj.scales": "model.safetensors",
|
| 804 |
+
"model.layers.8.mlp.up_proj.weight": "model.safetensors",
|
| 805 |
+
"model.layers.8.post_attention_layernorm.weight": "model.safetensors",
|
| 806 |
+
"model.layers.8.self_attn.k_proj.biases": "model.safetensors",
|
| 807 |
+
"model.layers.8.self_attn.k_proj.scales": "model.safetensors",
|
| 808 |
+
"model.layers.8.self_attn.k_proj.weight": "model.safetensors",
|
| 809 |
+
"model.layers.8.self_attn.o_proj.biases": "model.safetensors",
|
| 810 |
+
"model.layers.8.self_attn.o_proj.scales": "model.safetensors",
|
| 811 |
+
"model.layers.8.self_attn.o_proj.weight": "model.safetensors",
|
| 812 |
+
"model.layers.8.self_attn.q_proj.biases": "model.safetensors",
|
| 813 |
+
"model.layers.8.self_attn.q_proj.scales": "model.safetensors",
|
| 814 |
+
"model.layers.8.self_attn.q_proj.weight": "model.safetensors",
|
| 815 |
+
"model.layers.8.self_attn.v_proj.biases": "model.safetensors",
|
| 816 |
+
"model.layers.8.self_attn.v_proj.scales": "model.safetensors",
|
| 817 |
+
"model.layers.8.self_attn.v_proj.weight": "model.safetensors",
|
| 818 |
+
"model.layers.9.input_layernorm.weight": "model.safetensors",
|
| 819 |
+
"model.layers.9.mlp.down_proj.biases": "model.safetensors",
|
| 820 |
+
"model.layers.9.mlp.down_proj.scales": "model.safetensors",
|
| 821 |
+
"model.layers.9.mlp.down_proj.weight": "model.safetensors",
|
| 822 |
+
"model.layers.9.mlp.gate_proj.biases": "model.safetensors",
|
| 823 |
+
"model.layers.9.mlp.gate_proj.scales": "model.safetensors",
|
| 824 |
+
"model.layers.9.mlp.gate_proj.weight": "model.safetensors",
|
| 825 |
+
"model.layers.9.mlp.up_proj.biases": "model.safetensors",
|
| 826 |
+
"model.layers.9.mlp.up_proj.scales": "model.safetensors",
|
| 827 |
+
"model.layers.9.mlp.up_proj.weight": "model.safetensors",
|
| 828 |
+
"model.layers.9.post_attention_layernorm.weight": "model.safetensors",
|
| 829 |
+
"model.layers.9.self_attn.k_proj.biases": "model.safetensors",
|
| 830 |
+
"model.layers.9.self_attn.k_proj.scales": "model.safetensors",
|
| 831 |
+
"model.layers.9.self_attn.k_proj.weight": "model.safetensors",
|
| 832 |
+
"model.layers.9.self_attn.o_proj.biases": "model.safetensors",
|
| 833 |
+
"model.layers.9.self_attn.o_proj.scales": "model.safetensors",
|
| 834 |
+
"model.layers.9.self_attn.o_proj.weight": "model.safetensors",
|
| 835 |
+
"model.layers.9.self_attn.q_proj.biases": "model.safetensors",
|
| 836 |
+
"model.layers.9.self_attn.q_proj.scales": "model.safetensors",
|
| 837 |
+
"model.layers.9.self_attn.q_proj.weight": "model.safetensors",
|
| 838 |
+
"model.layers.9.self_attn.v_proj.biases": "model.safetensors",
|
| 839 |
+
"model.layers.9.self_attn.v_proj.scales": "model.safetensors",
|
| 840 |
+
"model.layers.9.self_attn.v_proj.weight": "model.safetensors",
|
| 841 |
+
"model.norm.weight": "model.safetensors"
|
| 842 |
+
}
|
| 843 |
+
}
|
modeling_k2_horizon.py
ADDED
|
@@ -0,0 +1,1116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/qwen3_moe/modular_qwen3_moe.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_qwen3_moe.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
# coding=utf-8
|
| 8 |
+
# Copyright 2025 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
| 9 |
+
#
|
| 10 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
# you may not use this file except in compliance with the License.
|
| 12 |
+
# You may obtain a copy of the License at
|
| 13 |
+
#
|
| 14 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
#
|
| 16 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
# See the License for the specific language governing permissions and
|
| 20 |
+
# limitations under the License.
|
| 21 |
+
|
| 22 |
+
from typing import Callable, Optional, Union
|
| 23 |
+
|
| 24 |
+
import math
|
| 25 |
+
import torch
|
| 26 |
+
import torch.nn.functional as F
|
| 27 |
+
from torch import nn
|
| 28 |
+
|
| 29 |
+
from transformers.activations import ACT2FN
|
| 30 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 31 |
+
from transformers.generation import GenerationMixin
|
| 32 |
+
from transformers.masking_utils import create_causal_mask, create_sliding_window_causal_mask
|
| 33 |
+
from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
|
| 34 |
+
from transformers.modeling_layers import (
|
| 35 |
+
GenericForQuestionAnswering,
|
| 36 |
+
GenericForSequenceClassification,
|
| 37 |
+
GenericForTokenClassification,
|
| 38 |
+
GradientCheckpointingLayer,
|
| 39 |
+
)
|
| 40 |
+
from transformers.modeling_outputs import MoeCausalLMOutputWithPast, MoeModelOutputWithPast
|
| 41 |
+
from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
|
| 42 |
+
from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
|
| 43 |
+
from transformers.processing_utils import Unpack
|
| 44 |
+
from transformers.utils import TransformersKwargs, auto_docstring, can_return_tuple
|
| 45 |
+
from transformers.utils.generic import maybe_autocast
|
| 46 |
+
from transformers.utils.deprecation import deprecate_kwarg
|
| 47 |
+
from transformers.utils.output_capturing import OutputRecorder
|
| 48 |
+
|
| 49 |
+
from .configuration_k2_horizon import K2HorizonConfig
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def rotate_half(x):
|
| 53 |
+
"""Rotates half the hidden dims of the input."""
|
| 54 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 55 |
+
x2 = x[..., x.shape[-1] // 2:]
|
| 56 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 60 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 61 |
+
|
| 62 |
+
Args:
|
| 63 |
+
q (`torch.Tensor`): The query tensor.
|
| 64 |
+
k (`torch.Tensor`): The key tensor.
|
| 65 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 66 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 67 |
+
position_ids (`torch.Tensor`, *optional*):
|
| 68 |
+
Deprecated and unused.
|
| 69 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 70 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 71 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 72 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 73 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 74 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 75 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 76 |
+
Returns:
|
| 77 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 78 |
+
"""
|
| 79 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 80 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 81 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 82 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 83 |
+
return q_embed, k_embed
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 87 |
+
"""
|
| 88 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 89 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 90 |
+
"""
|
| 91 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 92 |
+
if n_rep == 1:
|
| 93 |
+
return hidden_states
|
| 94 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 95 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def split_to_interleaved(x):
|
| 99 |
+
# Split halves: x0 x1 x2 x3 ... y0 y1 y2 y3 ...
|
| 100 |
+
# Interleaved: x0 y0 x1 y1 x2 y2 x3 y3 ...
|
| 101 |
+
return x.reshape(*x.shape[:-1], 2, -1).transpose(-1, -2).reshape(*x.shape[:-1], -1)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def interleaved_to_split(x):
|
| 105 |
+
# Interleaved: x0 y0 x1 y1 x2 y2 x3 y3 ...
|
| 106 |
+
# Split halves: x0 x1 x2 x3 ... y0 y1 y2 y3 ...
|
| 107 |
+
return x.reshape(*x.shape[:-1], -1, 2).transpose(-1, -2).reshape(*x.shape[:-1], -1)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def eager_attention_forward(
|
| 111 |
+
module: nn.Module,
|
| 112 |
+
query: torch.Tensor,
|
| 113 |
+
key: torch.Tensor,
|
| 114 |
+
value: torch.Tensor,
|
| 115 |
+
attention_mask: Optional[torch.Tensor],
|
| 116 |
+
scaling: float,
|
| 117 |
+
dropout: float = 0.0,
|
| 118 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 119 |
+
):
|
| 120 |
+
key_states = repeat_kv(key, module.num_key_value_groups)
|
| 121 |
+
value_states = repeat_kv(value, module.num_key_value_groups)
|
| 122 |
+
|
| 123 |
+
attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
|
| 124 |
+
if attention_mask is not None:
|
| 125 |
+
causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
|
| 126 |
+
attn_weights = attn_weights + causal_mask
|
| 127 |
+
|
| 128 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
|
| 129 |
+
attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
|
| 130 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 131 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 132 |
+
|
| 133 |
+
return attn_output, attn_weights
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def calc_router_weights(
|
| 137 |
+
router_logits: torch.Tensor,
|
| 138 |
+
router_bias: Optional[torch.Tensor],
|
| 139 |
+
score_func: str,
|
| 140 |
+
top_k: int,
|
| 141 |
+
scaling_factor: Optional[float],
|
| 142 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 143 |
+
"""Return native-XLLM-compatible routing weights and selected experts.
|
| 144 |
+
|
| 145 |
+
XLLM applies router bias only to the values used for top-k selection. The
|
| 146 |
+
selected routes are still weighted by the original router probabilities,
|
| 147 |
+
then optionally normalized and scaled.
|
| 148 |
+
"""
|
| 149 |
+
if score_func == "softmax":
|
| 150 |
+
routing_scores = F.softmax(router_logits, dim=-1, dtype=torch.float32)
|
| 151 |
+
elif score_func == "sigmoid":
|
| 152 |
+
routing_scores = torch.sigmoid(router_logits.to(torch.float32))
|
| 153 |
+
else:
|
| 154 |
+
raise ValueError(f"Unsupported router score function: {score_func}")
|
| 155 |
+
|
| 156 |
+
selection_scores = routing_scores
|
| 157 |
+
if router_bias is not None:
|
| 158 |
+
selection_scores = selection_scores + router_bias.to(selection_scores)
|
| 159 |
+
|
| 160 |
+
selected_indices = torch.topk(selection_scores, top_k, dim=-1).indices
|
| 161 |
+
routing_weights = torch.gather(routing_scores, dim=-1, index=selected_indices)
|
| 162 |
+
if top_k > 1:
|
| 163 |
+
routing_weights = routing_weights / routing_weights.sum(dim=-1, keepdim=True)
|
| 164 |
+
if scaling_factor is not None:
|
| 165 |
+
routing_weights = routing_weights * scaling_factor
|
| 166 |
+
return routing_weights, selected_indices
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def combine_routed_experts(
|
| 170 |
+
hidden_states: torch.Tensor,
|
| 171 |
+
routing_weights: torch.Tensor,
|
| 172 |
+
selected_indices: torch.Tensor,
|
| 173 |
+
experts: nn.ModuleList,
|
| 174 |
+
activation: Optional[Callable[[torch.Tensor], torch.Tensor]] = None,
|
| 175 |
+
) -> torch.Tensor:
|
| 176 |
+
num_tokens, hidden_dim = hidden_states.shape
|
| 177 |
+
final_hidden_states = torch.zeros(
|
| 178 |
+
(num_tokens, experts[0].out_features),
|
| 179 |
+
dtype=hidden_states.dtype,
|
| 180 |
+
device=hidden_states.device,
|
| 181 |
+
)
|
| 182 |
+
expert_mask = torch.nn.functional.one_hot(
|
| 183 |
+
selected_indices, num_classes=len(experts)
|
| 184 |
+
).permute(2, 1, 0)
|
| 185 |
+
|
| 186 |
+
for expert_idx in torch.nonzero(expert_mask.sum(dim=(-1, -2)), as_tuple=False).flatten():
|
| 187 |
+
topk_positions, token_positions = torch.where(expert_mask[int(expert_idx)])
|
| 188 |
+
expert_states = experts[int(expert_idx)](hidden_states[token_positions])
|
| 189 |
+
if activation is not None:
|
| 190 |
+
expert_states = activation(expert_states)
|
| 191 |
+
expert_states = expert_states * routing_weights[token_positions, topk_positions, None].to(expert_states.dtype)
|
| 192 |
+
final_hidden_states.index_add_(0, token_positions, expert_states.to(hidden_states.dtype))
|
| 193 |
+
|
| 194 |
+
return final_hidden_states
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
class K2HorizonAttention(nn.Module):
|
| 198 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 199 |
+
|
| 200 |
+
def __init__(self, config: K2HorizonConfig, layer_idx: int):
|
| 201 |
+
super().__init__()
|
| 202 |
+
self.config = config
|
| 203 |
+
self.layer_idx = layer_idx
|
| 204 |
+
self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
|
| 205 |
+
self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
|
| 206 |
+
self.scaling = self.head_dim ** -0.5
|
| 207 |
+
self.attention_dropout = config.attention_dropout
|
| 208 |
+
self.is_causal = True
|
| 209 |
+
|
| 210 |
+
self.rope_head_dim = self.head_dim if config.rope_head_dim is None else config.rope_head_dim
|
| 211 |
+
|
| 212 |
+
self.q_proj = nn.Linear(
|
| 213 |
+
config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
|
| 214 |
+
)
|
| 215 |
+
self.k_proj = nn.Linear(
|
| 216 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 217 |
+
)
|
| 218 |
+
self.v_proj = nn.Linear(
|
| 219 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 220 |
+
)
|
| 221 |
+
self.o_proj = nn.Linear(
|
| 222 |
+
config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
self.gate_func = config.attention_gate_func
|
| 226 |
+
if self.gate_func is not None:
|
| 227 |
+
self.gate_proj = nn.Linear(
|
| 228 |
+
config.hidden_size,
|
| 229 |
+
config.num_attention_heads * self.head_dim,
|
| 230 |
+
bias=False)
|
| 231 |
+
|
| 232 |
+
if config.query_key_norm:
|
| 233 |
+
self.q_norm = K2HorizonRMSNorm(
|
| 234 |
+
hidden_size=config.num_attention_heads * self.head_dim,
|
| 235 |
+
n_groups=config.num_attention_heads,
|
| 236 |
+
eps=config.rms_norm_eps)
|
| 237 |
+
self.k_norm = K2HorizonRMSNorm(
|
| 238 |
+
hidden_size=config.num_key_value_heads * self.head_dim,
|
| 239 |
+
n_groups=config.num_key_value_heads,
|
| 240 |
+
eps=config.rms_norm_eps)
|
| 241 |
+
|
| 242 |
+
self.sliding_window = getattr(config, "sliding_window", None)
|
| 243 |
+
|
| 244 |
+
@deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
|
| 245 |
+
def forward(
|
| 246 |
+
self,
|
| 247 |
+
hidden_states: torch.Tensor,
|
| 248 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 249 |
+
attention_mask: Optional[torch.Tensor],
|
| 250 |
+
past_key_values: Optional[Cache] = None,
|
| 251 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 252 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 253 |
+
) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
|
| 254 |
+
input_shape = hidden_states.shape[:-1]
|
| 255 |
+
hidden_shape = (*input_shape, -1, self.head_dim)
|
| 256 |
+
|
| 257 |
+
if self.config.query_key_norm:
|
| 258 |
+
query_states = self.q_norm(self.q_proj(hidden_states)).view(hidden_shape).transpose(1, 2)
|
| 259 |
+
key_states = self.k_norm(self.k_proj(hidden_states)).view(hidden_shape).transpose(1, 2)
|
| 260 |
+
else:
|
| 261 |
+
query_states = self.q_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 262 |
+
key_states = self.k_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 263 |
+
|
| 264 |
+
value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 265 |
+
|
| 266 |
+
cos, sin = position_embeddings
|
| 267 |
+
if self.rope_head_dim == self.head_dim:
|
| 268 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
|
| 269 |
+
else:
|
| 270 |
+
query_states, query_states_ = torch.split(
|
| 271 |
+
split_to_interleaved(query_states),
|
| 272 |
+
split_size_or_sections=[self.rope_head_dim, self.head_dim - self.rope_head_dim],
|
| 273 |
+
dim=-1)
|
| 274 |
+
|
| 275 |
+
key_states, key_states_ = torch.split(
|
| 276 |
+
split_to_interleaved(key_states),
|
| 277 |
+
split_size_or_sections=[self.rope_head_dim, self.head_dim - self.rope_head_dim],
|
| 278 |
+
dim=-1)
|
| 279 |
+
|
| 280 |
+
query_states, key_states = apply_rotary_pos_emb(
|
| 281 |
+
interleaved_to_split(query_states),
|
| 282 |
+
interleaved_to_split(key_states),
|
| 283 |
+
cos,
|
| 284 |
+
sin)
|
| 285 |
+
|
| 286 |
+
query_states = interleaved_to_split(torch.cat(
|
| 287 |
+
[split_to_interleaved(query_states), query_states_], dim=-1))
|
| 288 |
+
key_states = interleaved_to_split(torch.cat(
|
| 289 |
+
[split_to_interleaved(key_states), key_states_], dim=-1))
|
| 290 |
+
|
| 291 |
+
if past_key_values is not None:
|
| 292 |
+
# sin and cos are specific to RoPE models; cache_position needed for the static cache
|
| 293 |
+
cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
|
| 294 |
+
key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 295 |
+
|
| 296 |
+
attention_interface: Callable = eager_attention_forward
|
| 297 |
+
if self.config._attn_implementation != "eager":
|
| 298 |
+
attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
|
| 299 |
+
|
| 300 |
+
attn_output, attn_weights = attention_interface(
|
| 301 |
+
self,
|
| 302 |
+
query_states,
|
| 303 |
+
key_states,
|
| 304 |
+
value_states,
|
| 305 |
+
attention_mask,
|
| 306 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 307 |
+
scaling=self.scaling,
|
| 308 |
+
sliding_window=self.sliding_window, # diff with Llama
|
| 309 |
+
**kwargs,
|
| 310 |
+
)
|
| 311 |
+
|
| 312 |
+
if self.gate_func is not None:
|
| 313 |
+
gate = self.gate_proj(hidden_states).view(
|
| 314 |
+
input_shape + (-1, self.head_dim))
|
| 315 |
+
if self.gate_func == 'silu':
|
| 316 |
+
gate = F.silu(gate)
|
| 317 |
+
else:
|
| 318 |
+
assert self.gate_func == 'softplus'
|
| 319 |
+
gate = F.softplus(gate, beta=math.log(2))
|
| 320 |
+
|
| 321 |
+
attn_output = attn_output * gate
|
| 322 |
+
|
| 323 |
+
attn_output = attn_output.reshape(*input_shape, -1).contiguous()
|
| 324 |
+
attn_output = self.o_proj(attn_output)
|
| 325 |
+
return attn_output, attn_weights
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
def apply_rotary_pos_emb_xllm(q, k, freqs_cis):
|
| 329 |
+
if q.shape[-1] % 2 != 0 or k.shape[-1] % 2 != 0:
|
| 330 |
+
raise ValueError(f"RoPE dimensions must be even, got q={q.shape[-1]} and k={k.shape[-1]}")
|
| 331 |
+
q_ = torch.view_as_complex(q.float().reshape(*q.shape[:-1], -1, 2))
|
| 332 |
+
k_ = torch.view_as_complex(k.float().reshape(*k.shape[:-1], -1, 2))
|
| 333 |
+
if freqs_cis.ndim == 2:
|
| 334 |
+
freqs_cis = freqs_cis.unsqueeze(1)
|
| 335 |
+
elif freqs_cis.ndim == 3:
|
| 336 |
+
freqs_cis = freqs_cis.unsqueeze(2)
|
| 337 |
+
else:
|
| 338 |
+
raise ValueError(f"Unsupported freqs_cis shape: {tuple(freqs_cis.shape)}")
|
| 339 |
+
if freqs_cis.shape[-1] != q_.shape[-1] or freqs_cis.shape[-1] != k_.shape[-1]:
|
| 340 |
+
raise ValueError(
|
| 341 |
+
"RoPE frequency dimension mismatch: "
|
| 342 |
+
f"q_rope_dim={q.shape[-1]}, k_rope_dim={k.shape[-1]}, "
|
| 343 |
+
f"q_complex_dim={q_.shape[-1]}, k_complex_dim={k_.shape[-1]}, "
|
| 344 |
+
f"freqs_complex_dim={freqs_cis.shape[-1]}, freqs_shape={tuple(freqs_cis.shape)}"
|
| 345 |
+
)
|
| 346 |
+
q_embed = torch.view_as_real(q_ * freqs_cis).flatten(-2).to(q.dtype)
|
| 347 |
+
k_embed = torch.view_as_real(k_ * freqs_cis).flatten(-2).to(k.dtype)
|
| 348 |
+
return q_embed, k_embed
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
class K2HorizonMoVAAttention(nn.Module):
|
| 352 |
+
"""MoVA attention with routed value experts and optional post-attention gate."""
|
| 353 |
+
|
| 354 |
+
def __init__(self, config: K2HorizonConfig, layer_idx: int):
|
| 355 |
+
super().__init__()
|
| 356 |
+
self.config = config
|
| 357 |
+
self.layer_idx = layer_idx
|
| 358 |
+
self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
|
| 359 |
+
self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
|
| 360 |
+
self.scaling = self.head_dim**-0.5
|
| 361 |
+
self.attention_dropout = config.attention_dropout
|
| 362 |
+
self.is_causal = True
|
| 363 |
+
|
| 364 |
+
self.num_experts_per_tok = config.mova_num_experts_per_tok
|
| 365 |
+
self.router_score_func = config.router_score_func
|
| 366 |
+
self.router_scaling_factor = config.router_scaling_factor
|
| 367 |
+
self.gate_func = config.attention_gate_func
|
| 368 |
+
|
| 369 |
+
self.rope_head_dim = self.head_dim if config.rope_head_dim is None else config.rope_head_dim
|
| 370 |
+
|
| 371 |
+
self.q_proj = nn.Linear(
|
| 372 |
+
config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
|
| 373 |
+
)
|
| 374 |
+
self.k_proj = nn.Linear(
|
| 375 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 376 |
+
)
|
| 377 |
+
self.o_proj = nn.Linear(
|
| 378 |
+
config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
|
| 379 |
+
)
|
| 380 |
+
self.v_router = nn.Linear(
|
| 381 |
+
config.hidden_size,
|
| 382 |
+
config.mova_num_experts,
|
| 383 |
+
bias=config.moe_gate_bias)
|
| 384 |
+
self.v_experts = nn.ModuleList([
|
| 385 |
+
nn.Linear(
|
| 386 |
+
config.hidden_size,
|
| 387 |
+
config.num_key_value_heads * self.head_dim,
|
| 388 |
+
bias=False
|
| 389 |
+
) for _ in range(config.mova_num_experts)
|
| 390 |
+
])
|
| 391 |
+
|
| 392 |
+
if self.gate_func is not None:
|
| 393 |
+
self.gate_proj = nn.Linear(
|
| 394 |
+
config.hidden_size,
|
| 395 |
+
config.num_attention_heads * self.head_dim,
|
| 396 |
+
bias=False)
|
| 397 |
+
|
| 398 |
+
if config.query_key_norm:
|
| 399 |
+
self.q_norm = K2HorizonRMSNorm(
|
| 400 |
+
hidden_size=config.num_attention_heads * self.head_dim,
|
| 401 |
+
n_groups=config.num_attention_heads,
|
| 402 |
+
eps=config.rms_norm_eps,
|
| 403 |
+
)
|
| 404 |
+
self.k_norm = K2HorizonRMSNorm(
|
| 405 |
+
hidden_size=config.num_key_value_heads * self.head_dim,
|
| 406 |
+
n_groups=config.num_key_value_heads,
|
| 407 |
+
eps=config.rms_norm_eps,
|
| 408 |
+
)
|
| 409 |
+
|
| 410 |
+
self.sliding_window = getattr(config, "sliding_window", None)
|
| 411 |
+
|
| 412 |
+
@deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
|
| 413 |
+
def forward(
|
| 414 |
+
self,
|
| 415 |
+
hidden_states: torch.Tensor,
|
| 416 |
+
position_embeddings: torch.Tensor,
|
| 417 |
+
attention_mask: Optional[torch.Tensor],
|
| 418 |
+
past_key_values: Optional[Cache] = None,
|
| 419 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 420 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 421 |
+
) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
|
| 422 |
+
input_shape = hidden_states.shape[:-1]
|
| 423 |
+
hidden_shape = (*input_shape, -1, self.head_dim)
|
| 424 |
+
flat_hidden_states = hidden_states.reshape(-1, hidden_states.shape[-1])
|
| 425 |
+
|
| 426 |
+
# Match native MOVAttention router semantics exactly: compute logits with
|
| 427 |
+
# the weight-only linear and apply router bias only to selection scores.
|
| 428 |
+
router_logits = F.linear(flat_hidden_states, self.v_router.weight)
|
| 429 |
+
routing_weights, selected_values = calc_router_weights(
|
| 430 |
+
router_logits=router_logits,
|
| 431 |
+
router_bias=self.v_router.bias,
|
| 432 |
+
score_func=self.router_score_func,
|
| 433 |
+
top_k=self.num_experts_per_tok,
|
| 434 |
+
scaling_factor=self.router_scaling_factor,
|
| 435 |
+
)
|
| 436 |
+
|
| 437 |
+
mixed_value_states = combine_routed_experts(
|
| 438 |
+
hidden_states=flat_hidden_states,
|
| 439 |
+
routing_weights=routing_weights,
|
| 440 |
+
selected_indices=selected_values,
|
| 441 |
+
experts=self.v_experts,
|
| 442 |
+
activation=F.silu)
|
| 443 |
+
|
| 444 |
+
value_states = mixed_value_states.view(hidden_shape).transpose(1, 2)
|
| 445 |
+
|
| 446 |
+
if self.config.query_key_norm:
|
| 447 |
+
query_states = self.q_norm(self.q_proj(hidden_states)).view(hidden_shape).transpose(1, 2)
|
| 448 |
+
key_states = self.k_norm(self.k_proj(hidden_states)).view(hidden_shape).transpose(1, 2)
|
| 449 |
+
else:
|
| 450 |
+
query_states = self.q_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 451 |
+
key_states = self.k_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 452 |
+
|
| 453 |
+
cos, sin = position_embeddings
|
| 454 |
+
if self.rope_head_dim == self.head_dim:
|
| 455 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
|
| 456 |
+
else:
|
| 457 |
+
query_states, query_states_ = torch.split(
|
| 458 |
+
split_to_interleaved(query_states),
|
| 459 |
+
split_size_or_sections=[self.rope_head_dim, self.head_dim - self.rope_head_dim],
|
| 460 |
+
dim=-1)
|
| 461 |
+
|
| 462 |
+
key_states, key_states_ = torch.split(
|
| 463 |
+
split_to_interleaved(key_states),
|
| 464 |
+
split_size_or_sections=[self.rope_head_dim, self.head_dim - self.rope_head_dim],
|
| 465 |
+
dim=-1)
|
| 466 |
+
|
| 467 |
+
query_states, key_states = apply_rotary_pos_emb(
|
| 468 |
+
interleaved_to_split(query_states),
|
| 469 |
+
interleaved_to_split(key_states),
|
| 470 |
+
cos,
|
| 471 |
+
sin)
|
| 472 |
+
|
| 473 |
+
query_states = interleaved_to_split(torch.cat(
|
| 474 |
+
[split_to_interleaved(query_states), query_states_], dim=-1))
|
| 475 |
+
key_states = interleaved_to_split(torch.cat(
|
| 476 |
+
[split_to_interleaved(key_states), key_states_], dim=-1))
|
| 477 |
+
|
| 478 |
+
if past_key_values is not None:
|
| 479 |
+
cache_kwargs = {"cache_position": cache_position}
|
| 480 |
+
key_states, value_states = past_key_values.update(
|
| 481 |
+
key_states, value_states, self.layer_idx, cache_kwargs
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
attention_interface: Callable = eager_attention_forward
|
| 485 |
+
if self.config._attn_implementation != "eager":
|
| 486 |
+
attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
|
| 487 |
+
|
| 488 |
+
attn_output, attn_weights = attention_interface(
|
| 489 |
+
self,
|
| 490 |
+
query_states,
|
| 491 |
+
key_states,
|
| 492 |
+
value_states,
|
| 493 |
+
attention_mask,
|
| 494 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 495 |
+
scaling=self.scaling,
|
| 496 |
+
sliding_window=self.sliding_window,
|
| 497 |
+
**kwargs,
|
| 498 |
+
)
|
| 499 |
+
|
| 500 |
+
if self.gate_func is not None:
|
| 501 |
+
gate = self.gate_proj(hidden_states).view(input_shape + (-1, self.head_dim))
|
| 502 |
+
if self.gate_func == 'silu':
|
| 503 |
+
gate = F.silu(gate)
|
| 504 |
+
else:
|
| 505 |
+
assert self.gate_func == 'softplus'
|
| 506 |
+
gate = F.softplus(gate, beta=math.log(2))
|
| 507 |
+
|
| 508 |
+
attn_output = attn_output * gate
|
| 509 |
+
|
| 510 |
+
attn_output = attn_output.reshape(*input_shape, -1).contiguous()
|
| 511 |
+
attn_output = self.o_proj(attn_output)
|
| 512 |
+
return attn_output, attn_weights
|
| 513 |
+
|
| 514 |
+
|
| 515 |
+
class K2HorizonMLP(nn.Module):
|
| 516 |
+
def __init__(self, config, intermediate_size=None):
|
| 517 |
+
super().__init__()
|
| 518 |
+
self.config = config
|
| 519 |
+
self.hidden_size = config.hidden_size
|
| 520 |
+
self.intermediate_size = intermediate_size if intermediate_size is not None else config.intermediate_size
|
| 521 |
+
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 522 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 523 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
|
| 524 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
| 525 |
+
|
| 526 |
+
def forward(self, x):
|
| 527 |
+
down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
| 528 |
+
return down_proj
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
class K2HorizonSparseMoeBlock(nn.Module):
|
| 532 |
+
def __init__(self, config):
|
| 533 |
+
super().__init__()
|
| 534 |
+
self.num_experts = config.num_experts
|
| 535 |
+
self.top_k = config.num_experts_per_tok
|
| 536 |
+
self.norm_topk_prob = config.norm_topk_prob
|
| 537 |
+
self.num_shared_experts = config.num_shared_experts
|
| 538 |
+
self.router_score_func = config.router_score_func
|
| 539 |
+
self.router_scaling_factor = config.router_scaling_factor
|
| 540 |
+
|
| 541 |
+
# gating
|
| 542 |
+
self.gate = nn.Linear(config.hidden_size, config.num_experts, bias=config.moe_gate_bias)
|
| 543 |
+
self.experts = nn.ModuleList(
|
| 544 |
+
[K2HorizonMLP(config, intermediate_size=config.moe_intermediate_size) for _ in range(self.num_experts)]
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
+
if config.num_shared_experts > 0:
|
| 548 |
+
self.shared_experts = K2HorizonMLP(
|
| 549 |
+
config=config,
|
| 550 |
+
intermediate_size=config.moe_intermediate_size * config.num_shared_experts)
|
| 551 |
+
|
| 552 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 553 |
+
""" """
|
| 554 |
+
residuals = hidden_states
|
| 555 |
+
|
| 556 |
+
batch_size, sequence_length, hidden_dim = hidden_states.shape
|
| 557 |
+
hidden_states = hidden_states.view(-1, hidden_dim)
|
| 558 |
+
# router_logits: (batch * sequence_length, n_experts)
|
| 559 |
+
# router_logits = self.gate(hidden_states)
|
| 560 |
+
router_logits = F.linear(hidden_states, self.gate.weight)
|
| 561 |
+
|
| 562 |
+
if self.router_score_func == "softmax":
|
| 563 |
+
routing_weights = F.softmax(router_logits, dim=1, dtype=torch.float)
|
| 564 |
+
else:
|
| 565 |
+
assert self.router_score_func == "sigmoid"
|
| 566 |
+
routing_weights = F.sigmoid(router_logits.to(torch.float32))
|
| 567 |
+
|
| 568 |
+
routing_weights_for_choice = routing_weights
|
| 569 |
+
if self.gate.bias is not None:
|
| 570 |
+
routing_weights_for_choice = routing_weights + self.gate.bias.to(routing_weights.dtype)
|
| 571 |
+
|
| 572 |
+
_, selected_experts = torch.topk(routing_weights_for_choice, self.top_k, dim=-1)
|
| 573 |
+
routing_weights = torch.gather(routing_weights, dim=-1, index=selected_experts)
|
| 574 |
+
|
| 575 |
+
if self.norm_topk_prob: # only diff with mixtral sparse moe block!
|
| 576 |
+
routing_weights /= routing_weights.sum(dim=-1, keepdim=True)
|
| 577 |
+
routing_weights = routing_weights * self.router_scaling_factor
|
| 578 |
+
# we cast back to the input dtype
|
| 579 |
+
routing_weights = routing_weights.to(hidden_states.dtype)
|
| 580 |
+
|
| 581 |
+
final_hidden_states = torch.zeros(
|
| 582 |
+
(batch_size * sequence_length, hidden_dim), dtype=hidden_states.dtype, device=hidden_states.device
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
# One hot encode the selected experts to create an expert mask
|
| 586 |
+
# this will be used to easily index which expert is going to be sollicitated
|
| 587 |
+
expert_mask = torch.nn.functional.one_hot(selected_experts, num_classes=self.num_experts).permute(2, 1, 0)
|
| 588 |
+
|
| 589 |
+
# Loop over all available experts in the model and perform the computation on each expert
|
| 590 |
+
expert_hit = torch.greater(expert_mask.sum(dim=(-1, -2)), 0).nonzero()
|
| 591 |
+
for expert_idx in expert_hit:
|
| 592 |
+
expert_layer = self.experts[expert_idx]
|
| 593 |
+
idx, top_x = torch.where(expert_mask[expert_idx].squeeze(0))
|
| 594 |
+
|
| 595 |
+
# Index the correct hidden states and compute the expert hidden state for
|
| 596 |
+
# the current expert. We need to make sure to multiply the output hidden
|
| 597 |
+
# states by `routing_weights` on the corresponding tokens (top-1 and top-2)
|
| 598 |
+
current_state = hidden_states[None, top_x].reshape(-1, hidden_dim)
|
| 599 |
+
current_hidden_states = expert_layer(current_state) * routing_weights[top_x, idx, None]
|
| 600 |
+
|
| 601 |
+
# However `index_add_` only support torch tensors for indexing so we'll use
|
| 602 |
+
# the `top_x` tensor here.
|
| 603 |
+
final_hidden_states.index_add_(0, top_x, current_hidden_states.to(hidden_states.dtype))
|
| 604 |
+
final_hidden_states = final_hidden_states.reshape(batch_size, sequence_length, hidden_dim)
|
| 605 |
+
|
| 606 |
+
if self.num_shared_experts > 0:
|
| 607 |
+
final_hidden_states = final_hidden_states + self.shared_experts(residuals)
|
| 608 |
+
|
| 609 |
+
return final_hidden_states, router_logits
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
# @use_kernel_forward_from_hub("RMSNorm")
|
| 613 |
+
class K2HorizonRMSNorm(nn.Module):
|
| 614 |
+
def __init__(self, hidden_size: int, n_groups: int, eps=1e-6):
|
| 615 |
+
"""
|
| 616 |
+
K2HorizonRMSNorm is equivalent to T5LayerNorm
|
| 617 |
+
"""
|
| 618 |
+
super().__init__()
|
| 619 |
+
self.n_groups = n_groups
|
| 620 |
+
self.hidden_size = hidden_size
|
| 621 |
+
assert hidden_size % n_groups == 0
|
| 622 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 623 |
+
self.variance_epsilon = eps
|
| 624 |
+
|
| 625 |
+
def forward(self, hidden_states):
|
| 626 |
+
input_dtype = hidden_states.dtype
|
| 627 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 628 |
+
|
| 629 |
+
hidden_states = hidden_states.reshape(*hidden_states.shape[:-1], self.n_groups, -1)
|
| 630 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 631 |
+
|
| 632 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 633 |
+
hidden_states = hidden_states.reshape(*hidden_states.shape[:-2], -1)
|
| 634 |
+
hidden_states = self.weight * hidden_states
|
| 635 |
+
|
| 636 |
+
return hidden_states.to(input_dtype)
|
| 637 |
+
|
| 638 |
+
def extra_repr(self):
|
| 639 |
+
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
|
| 640 |
+
|
| 641 |
+
|
| 642 |
+
class K2HorizonDecoderLayer(GradientCheckpointingLayer):
|
| 643 |
+
def __init__(self, config: K2HorizonConfig, layer_idx: int):
|
| 644 |
+
super().__init__()
|
| 645 |
+
self.hidden_size = config.hidden_size
|
| 646 |
+
|
| 647 |
+
is_sparse_layer = (layer_idx not in config.mlp_only_layers) and (
|
| 648 |
+
config.num_experts > 0 and (layer_idx + 1) % config.decoder_sparse_step == 0)
|
| 649 |
+
|
| 650 |
+
if is_sparse_layer and config.mova_num_experts > 0:
|
| 651 |
+
self.self_attn = K2HorizonMoVAAttention(config=config, layer_idx=layer_idx)
|
| 652 |
+
else:
|
| 653 |
+
self.self_attn = K2HorizonAttention(config, layer_idx)
|
| 654 |
+
|
| 655 |
+
if is_sparse_layer:
|
| 656 |
+
self.mlp = K2HorizonSparseMoeBlock(config)
|
| 657 |
+
else:
|
| 658 |
+
self.mlp = K2HorizonMLP(config, intermediate_size=config.intermediate_size)
|
| 659 |
+
|
| 660 |
+
assert config.hidden_size % config.layernorm_num_groups == 0
|
| 661 |
+
self.input_layernorm = K2HorizonRMSNorm(
|
| 662 |
+
hidden_size=config.hidden_size,
|
| 663 |
+
n_groups=config.layernorm_num_groups,
|
| 664 |
+
eps=config.rms_norm_eps)
|
| 665 |
+
self.post_attention_layernorm = K2HorizonRMSNorm(
|
| 666 |
+
hidden_size=config.hidden_size,
|
| 667 |
+
n_groups=config.layernorm_num_groups,
|
| 668 |
+
eps=config.rms_norm_eps)
|
| 669 |
+
|
| 670 |
+
@deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
|
| 671 |
+
def forward(
|
| 672 |
+
self,
|
| 673 |
+
hidden_states: torch.Tensor,
|
| 674 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 675 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 676 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 677 |
+
past_key_values: Optional[Cache] = None,
|
| 678 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 679 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 680 |
+
) -> torch.FloatTensor:
|
| 681 |
+
"""
|
| 682 |
+
Args:
|
| 683 |
+
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
|
| 684 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
| 685 |
+
`(batch, sequence_length)` where padding elements are indicated by 0.
|
| 686 |
+
output_attentions (`bool`, *optional*):
|
| 687 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 688 |
+
returned tensors for more detail.
|
| 689 |
+
output_router_logits (`bool`, *optional*):
|
| 690 |
+
Whether or not to return the logits of all the routers. They are useful for computing the router loss,
|
| 691 |
+
and should not be returned during inference.
|
| 692 |
+
use_cache (`bool`, *optional*):
|
| 693 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
| 694 |
+
(see `past_key_values`).
|
| 695 |
+
past_key_values (`Cache`, *optional*): cached past key and value projection states
|
| 696 |
+
cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
|
| 697 |
+
Indices depicting the position of the input sequence tokens in the sequence.
|
| 698 |
+
position_embeddings (`tuple[torch.FloatTensor, torch.FloatTensor]`, *optional*):
|
| 699 |
+
Tuple containing the cosine and sine positional embeddings of shape `(batch_size, seq_len, head_dim)`,
|
| 700 |
+
with `head_dim` being the embedding dimension of each attention head.
|
| 701 |
+
kwargs (`dict`, *optional*):
|
| 702 |
+
Arbitrary kwargs to be ignored, used for FSDP and other methods that injects code
|
| 703 |
+
into the model
|
| 704 |
+
"""
|
| 705 |
+
residual = hidden_states
|
| 706 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 707 |
+
|
| 708 |
+
# Self Attention
|
| 709 |
+
hidden_states, _ = self.self_attn(
|
| 710 |
+
hidden_states=hidden_states,
|
| 711 |
+
position_embeddings=position_embeddings,
|
| 712 |
+
attention_mask=attention_mask,
|
| 713 |
+
position_ids=position_ids,
|
| 714 |
+
past_key_values=past_key_values,
|
| 715 |
+
cache_position=cache_position,
|
| 716 |
+
**kwargs,
|
| 717 |
+
)
|
| 718 |
+
|
| 719 |
+
hidden_states = residual + hidden_states
|
| 720 |
+
|
| 721 |
+
# Fully Connected
|
| 722 |
+
residual = hidden_states
|
| 723 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 724 |
+
hidden_states = self.mlp(hidden_states)
|
| 725 |
+
# For the MoE layers, we need to unpack
|
| 726 |
+
if isinstance(hidden_states, tuple):
|
| 727 |
+
hidden_states, _ = hidden_states
|
| 728 |
+
hidden_states = residual + hidden_states
|
| 729 |
+
|
| 730 |
+
return hidden_states
|
| 731 |
+
|
| 732 |
+
|
| 733 |
+
class K2HorizonRotaryEmbedding(nn.Module):
|
| 734 |
+
inv_freq: torch.Tensor # fix linting for `register_buffer`
|
| 735 |
+
|
| 736 |
+
def __init__(self, config: K2HorizonConfig, device=None):
|
| 737 |
+
super().__init__()
|
| 738 |
+
self.max_seq_len_cached = config.max_position_embeddings
|
| 739 |
+
self.original_max_seq_len = config.max_position_embeddings
|
| 740 |
+
|
| 741 |
+
self.config = config
|
| 742 |
+
|
| 743 |
+
self.rope_type = self.config.rope_parameters["rope_type"]
|
| 744 |
+
rope_init_fn: Callable = self.compute_default_rope_parameters
|
| 745 |
+
if self.rope_type != "default":
|
| 746 |
+
rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
|
| 747 |
+
inv_freq, self.attention_scaling = rope_init_fn(self.config, device)
|
| 748 |
+
|
| 749 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 750 |
+
self.register_buffer("original_inv_freq", inv_freq.clone(), persistent=False)
|
| 751 |
+
|
| 752 |
+
@staticmethod
|
| 753 |
+
def compute_default_rope_parameters(
|
| 754 |
+
config: K2HorizonConfig | None = None,
|
| 755 |
+
device: Optional["torch.device"] = None,
|
| 756 |
+
seq_len: int | None = None,
|
| 757 |
+
) -> tuple["torch.Tensor", float]:
|
| 758 |
+
"""
|
| 759 |
+
Computes the inverse frequencies according to the original RoPE implementation
|
| 760 |
+
Args:
|
| 761 |
+
config ([`~transformers.PreTrainedConfig`]):
|
| 762 |
+
The model configuration.
|
| 763 |
+
device (`torch.device`):
|
| 764 |
+
The device to use for initialization of the inverse frequencies.
|
| 765 |
+
seq_len (`int`, *optional*):
|
| 766 |
+
The current sequence length. Unused for this type of RoPE.
|
| 767 |
+
Returns:
|
| 768 |
+
Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
|
| 769 |
+
post-processing scaling factor applied to the computed cos/sin (unused in this type of RoPE).
|
| 770 |
+
"""
|
| 771 |
+
base = config.rope_parameters["rope_theta"]
|
| 772 |
+
# dim = getattr(config, "head_dim", None) or config.hidden_size // config.num_attention_heads
|
| 773 |
+
dim = (
|
| 774 |
+
config.rope_head_dim
|
| 775 |
+
if config.rope_head_dim is not None
|
| 776 |
+
else getattr(config, "head_dim", None) or config.hidden_size // config.num_attention_heads
|
| 777 |
+
)
|
| 778 |
+
|
| 779 |
+
attention_factor = 1.0 # Unused in this type of RoPE
|
| 780 |
+
|
| 781 |
+
# Compute the inverse frequencies
|
| 782 |
+
inv_freq = 1.0 / (
|
| 783 |
+
base ** (torch.arange(0, dim, 2, dtype=torch.int64).to(device=device, dtype=torch.float) / dim)
|
| 784 |
+
)
|
| 785 |
+
return inv_freq, attention_factor
|
| 786 |
+
|
| 787 |
+
@torch.no_grad()
|
| 788 |
+
@dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
|
| 789 |
+
def forward(self, x, position_ids):
|
| 790 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
|
| 791 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 792 |
+
|
| 793 |
+
device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
|
| 794 |
+
with maybe_autocast(device_type=device_type, enabled=False): # Force float32
|
| 795 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 796 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 797 |
+
cos = emb.cos() * self.attention_scaling
|
| 798 |
+
sin = emb.sin() * self.attention_scaling
|
| 799 |
+
|
| 800 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 801 |
+
|
| 802 |
+
|
| 803 |
+
@auto_docstring
|
| 804 |
+
class K2HorizonPreTrainedModel(PreTrainedModel):
|
| 805 |
+
config: K2HorizonConfig
|
| 806 |
+
base_model_prefix = "model"
|
| 807 |
+
supports_gradient_checkpointing = True
|
| 808 |
+
_no_split_modules = ["K2HorizonDecoderLayer"]
|
| 809 |
+
_skip_keys_device_placement = ["past_key_values"]
|
| 810 |
+
_supports_flash_attn = True
|
| 811 |
+
_supports_sdpa = True
|
| 812 |
+
_supports_flex_attn = True
|
| 813 |
+
_can_compile_fullgraph = False # MoE models don't work with torch.compile (`torch.where(condition)` not supported)
|
| 814 |
+
_supports_attention_backend = True
|
| 815 |
+
_can_record_outputs = {
|
| 816 |
+
"router_logits": OutputRecorder(K2HorizonSparseMoeBlock, index=1),
|
| 817 |
+
"hidden_states": K2HorizonDecoderLayer,
|
| 818 |
+
"attentions": K2HorizonAttention,
|
| 819 |
+
}
|
| 820 |
+
|
| 821 |
+
|
| 822 |
+
@auto_docstring
|
| 823 |
+
class K2HorizonModel(K2HorizonPreTrainedModel):
|
| 824 |
+
def __init__(self, config: K2HorizonConfig):
|
| 825 |
+
super().__init__(config)
|
| 826 |
+
# self.padding_idx = config.pad_token_id
|
| 827 |
+
self.padding_idx = getattr(config, "padding_idx", None)
|
| 828 |
+
self.vocab_size = config.vocab_size
|
| 829 |
+
|
| 830 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 831 |
+
self.layers = nn.ModuleList(
|
| 832 |
+
[K2HorizonDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 833 |
+
)
|
| 834 |
+
|
| 835 |
+
assert config.hidden_size % config.layernorm_num_groups == 0
|
| 836 |
+
self.norm = K2HorizonRMSNorm(
|
| 837 |
+
hidden_size=config.hidden_size,
|
| 838 |
+
n_groups=config.layernorm_num_groups,
|
| 839 |
+
eps=config.rms_norm_eps)
|
| 840 |
+
|
| 841 |
+
self.rotary_emb = K2HorizonRotaryEmbedding(config=config)
|
| 842 |
+
self.gradient_checkpointing = False
|
| 843 |
+
|
| 844 |
+
# Initialize weights and apply final processing
|
| 845 |
+
self.post_init()
|
| 846 |
+
|
| 847 |
+
@auto_docstring
|
| 848 |
+
def forward(
|
| 849 |
+
self,
|
| 850 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 851 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 852 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 853 |
+
past_key_values: Optional[Cache] = None,
|
| 854 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 855 |
+
use_cache: Optional[bool] = None,
|
| 856 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 857 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 858 |
+
) -> MoeModelOutputWithPast:
|
| 859 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 860 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 861 |
+
|
| 862 |
+
if use_cache and past_key_values is None:
|
| 863 |
+
past_key_values = DynamicCache(config=self.config)
|
| 864 |
+
|
| 865 |
+
if inputs_embeds is None:
|
| 866 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 867 |
+
|
| 868 |
+
if cache_position is None:
|
| 869 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 870 |
+
cache_position = torch.arange(
|
| 871 |
+
past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
|
| 872 |
+
)
|
| 873 |
+
if position_ids is None:
|
| 874 |
+
position_ids = cache_position.unsqueeze(0)
|
| 875 |
+
|
| 876 |
+
mask_function = create_causal_mask if self.config.sliding_window is None else create_sliding_window_causal_mask
|
| 877 |
+
causal_mask = mask_function(
|
| 878 |
+
config=self.config,
|
| 879 |
+
inputs_embeds=inputs_embeds,
|
| 880 |
+
attention_mask=attention_mask,
|
| 881 |
+
past_key_values=past_key_values,
|
| 882 |
+
position_ids=position_ids,
|
| 883 |
+
)
|
| 884 |
+
|
| 885 |
+
hidden_states = inputs_embeds
|
| 886 |
+
|
| 887 |
+
# create position embeddings to be shared across the decoder layers
|
| 888 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 889 |
+
|
| 890 |
+
for layer_idx, decoder_layer in enumerate(self.layers[: self.config.num_hidden_layers]):
|
| 891 |
+
hidden_states = decoder_layer(
|
| 892 |
+
hidden_states,
|
| 893 |
+
position_embeddings=position_embeddings,
|
| 894 |
+
attention_mask=causal_mask,
|
| 895 |
+
position_ids=position_ids,
|
| 896 |
+
past_key_values=past_key_values,
|
| 897 |
+
use_cache=use_cache,
|
| 898 |
+
cache_position=cache_position,
|
| 899 |
+
**kwargs,
|
| 900 |
+
)
|
| 901 |
+
|
| 902 |
+
hidden_states = self.norm(hidden_states)
|
| 903 |
+
|
| 904 |
+
return MoeModelOutputWithPast( # only diff with Mistral is the output type, we need MoE
|
| 905 |
+
last_hidden_state=hidden_states,
|
| 906 |
+
past_key_values=past_key_values,
|
| 907 |
+
)
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
def load_balancing_loss_func(
|
| 911 |
+
gate_logits: Union[torch.Tensor, tuple[torch.Tensor], None],
|
| 912 |
+
num_experts: Optional[int] = None,
|
| 913 |
+
top_k=2,
|
| 914 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 915 |
+
) -> Union[torch.Tensor, int]:
|
| 916 |
+
r"""
|
| 917 |
+
Computes auxiliary load balancing loss as in Switch Transformer - implemented in Pytorch.
|
| 918 |
+
|
| 919 |
+
See Switch Transformer (https://huggingface.co/papers/2101.03961) for more details. This function implements the loss
|
| 920 |
+
function presented in equations (4) - (6) of the paper. It aims at penalizing cases where the routing between
|
| 921 |
+
experts is too unbalanced.
|
| 922 |
+
|
| 923 |
+
Args:
|
| 924 |
+
gate_logits:
|
| 925 |
+
Logits from the `gate`, should be a tuple of model.config.num_hidden_layers tensors of
|
| 926 |
+
shape [batch_size X sequence_length, num_experts].
|
| 927 |
+
num_experts:
|
| 928 |
+
Number of experts
|
| 929 |
+
top_k:
|
| 930 |
+
The number of experts to route per-token, can be also interpreted as the `top-k` routing
|
| 931 |
+
parameter.
|
| 932 |
+
attention_mask (`torch.Tensor`, *optional*):
|
| 933 |
+
The attention_mask used in forward function
|
| 934 |
+
shape [batch_size X sequence_length] if not None.
|
| 935 |
+
|
| 936 |
+
Returns:
|
| 937 |
+
The auxiliary loss.
|
| 938 |
+
"""
|
| 939 |
+
if gate_logits is None or not isinstance(gate_logits, tuple):
|
| 940 |
+
return 0
|
| 941 |
+
|
| 942 |
+
if isinstance(gate_logits, tuple):
|
| 943 |
+
compute_device = gate_logits[0].device
|
| 944 |
+
concatenated_gate_logits = torch.cat([layer_gate.to(compute_device) for layer_gate in gate_logits], dim=0)
|
| 945 |
+
|
| 946 |
+
routing_weights = torch.nn.functional.softmax(concatenated_gate_logits, dim=-1)
|
| 947 |
+
|
| 948 |
+
_, selected_experts = torch.topk(routing_weights, top_k, dim=-1)
|
| 949 |
+
|
| 950 |
+
expert_mask = torch.nn.functional.one_hot(selected_experts, num_experts)
|
| 951 |
+
|
| 952 |
+
if attention_mask is None:
|
| 953 |
+
# Compute the percentage of tokens routed to each experts
|
| 954 |
+
tokens_per_expert = torch.mean(expert_mask.float(), dim=0)
|
| 955 |
+
|
| 956 |
+
# Compute the average probability of routing to these experts
|
| 957 |
+
router_prob_per_expert = torch.mean(routing_weights, dim=0)
|
| 958 |
+
else:
|
| 959 |
+
batch_size, sequence_length = attention_mask.shape
|
| 960 |
+
num_hidden_layers = concatenated_gate_logits.shape[0] // (batch_size * sequence_length)
|
| 961 |
+
|
| 962 |
+
# Compute the mask that masks all padding tokens as 0 with the same shape of expert_mask
|
| 963 |
+
expert_attention_mask = (
|
| 964 |
+
attention_mask[None, :, :, None, None]
|
| 965 |
+
.expand((num_hidden_layers, batch_size, sequence_length, top_k, num_experts))
|
| 966 |
+
.reshape(-1, top_k, num_experts)
|
| 967 |
+
.to(compute_device)
|
| 968 |
+
)
|
| 969 |
+
|
| 970 |
+
# Compute the percentage of tokens routed to each experts
|
| 971 |
+
tokens_per_expert = torch.sum(expert_mask.float() * expert_attention_mask, dim=0) / torch.sum(
|
| 972 |
+
expert_attention_mask, dim=0
|
| 973 |
+
)
|
| 974 |
+
|
| 975 |
+
# Compute the mask that masks all padding tokens as 0 with the same shape of tokens_per_expert
|
| 976 |
+
router_per_expert_attention_mask = (
|
| 977 |
+
attention_mask[None, :, :, None]
|
| 978 |
+
.expand((num_hidden_layers, batch_size, sequence_length, num_experts))
|
| 979 |
+
.reshape(-1, num_experts)
|
| 980 |
+
.to(compute_device)
|
| 981 |
+
)
|
| 982 |
+
|
| 983 |
+
# Compute the average probability of routing to these experts
|
| 984 |
+
router_prob_per_expert = torch.sum(routing_weights * router_per_expert_attention_mask, dim=0) / torch.sum(
|
| 985 |
+
router_per_expert_attention_mask, dim=0
|
| 986 |
+
)
|
| 987 |
+
|
| 988 |
+
overall_loss = torch.sum(tokens_per_expert * router_prob_per_expert.unsqueeze(0))
|
| 989 |
+
return overall_loss * num_experts
|
| 990 |
+
|
| 991 |
+
|
| 992 |
+
@auto_docstring
|
| 993 |
+
class K2HorizonForCausalLM(K2HorizonPreTrainedModel, GenerationMixin):
|
| 994 |
+
# _tied_weights_keys = ["lm_head.weight"]
|
| 995 |
+
# _tp_plan = {"lm_head": "colwise_rep"}
|
| 996 |
+
# _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
|
| 997 |
+
|
| 998 |
+
def __init__(self, config):
|
| 999 |
+
super().__init__(config)
|
| 1000 |
+
self.model = K2HorizonModel(config)
|
| 1001 |
+
self.vocab_size = config.vocab_size
|
| 1002 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 1003 |
+
self.router_aux_loss_coef = config.router_aux_loss_coef
|
| 1004 |
+
self.num_experts = config.num_experts
|
| 1005 |
+
self.num_experts_per_tok = config.num_experts_per_tok
|
| 1006 |
+
|
| 1007 |
+
# Initialize weights and apply final processing
|
| 1008 |
+
self.post_init()
|
| 1009 |
+
|
| 1010 |
+
@can_return_tuple
|
| 1011 |
+
@auto_docstring
|
| 1012 |
+
def forward(
|
| 1013 |
+
self,
|
| 1014 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1015 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1016 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1017 |
+
past_key_values: Optional[Cache] = None,
|
| 1018 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1019 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1020 |
+
use_cache: Optional[bool] = None,
|
| 1021 |
+
output_router_logits: Optional[bool] = None,
|
| 1022 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 1023 |
+
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 1024 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 1025 |
+
) -> MoeCausalLMOutputWithPast:
|
| 1026 |
+
r"""
|
| 1027 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1028 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 1029 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 1030 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 1031 |
+
|
| 1032 |
+
Example:
|
| 1033 |
+
|
| 1034 |
+
```python
|
| 1035 |
+
>>> from transformers import AutoTokenizer, K2HorizonForCausalLM
|
| 1036 |
+
|
| 1037 |
+
>>> model = K2HorizonForCausalLM.from_pretrained("Qwen/Qwen3-MoE-15B-A2B")
|
| 1038 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-MoE-15B-A2B")
|
| 1039 |
+
|
| 1040 |
+
>>> prompt = "Hey, are you conscious? Can you talk to me?"
|
| 1041 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
| 1042 |
+
|
| 1043 |
+
>>> # Generate
|
| 1044 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
| 1045 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 1046 |
+
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
|
| 1047 |
+
```"""
|
| 1048 |
+
|
| 1049 |
+
output_router_logits = (
|
| 1050 |
+
output_router_logits if output_router_logits is not None else self.config.output_router_logits
|
| 1051 |
+
)
|
| 1052 |
+
|
| 1053 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 1054 |
+
outputs: MoeModelOutputWithPast = self.model(
|
| 1055 |
+
input_ids=input_ids,
|
| 1056 |
+
attention_mask=attention_mask,
|
| 1057 |
+
position_ids=position_ids,
|
| 1058 |
+
past_key_values=past_key_values,
|
| 1059 |
+
inputs_embeds=inputs_embeds,
|
| 1060 |
+
use_cache=use_cache,
|
| 1061 |
+
output_router_logits=output_router_logits,
|
| 1062 |
+
cache_position=cache_position,
|
| 1063 |
+
**kwargs,
|
| 1064 |
+
)
|
| 1065 |
+
|
| 1066 |
+
hidden_states = outputs.last_hidden_state
|
| 1067 |
+
# Only compute necessary logits, and do not upcast them to float if we are not computing the loss
|
| 1068 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 1069 |
+
logits = self.lm_head(hidden_states[:, slice_indices, :])
|
| 1070 |
+
|
| 1071 |
+
loss = None
|
| 1072 |
+
if labels is not None:
|
| 1073 |
+
loss = self.loss_function(logits, labels, self.vocab_size, **kwargs)
|
| 1074 |
+
|
| 1075 |
+
aux_loss = None
|
| 1076 |
+
if output_router_logits:
|
| 1077 |
+
aux_loss = load_balancing_loss_func(
|
| 1078 |
+
outputs.router_logits,
|
| 1079 |
+
self.num_experts,
|
| 1080 |
+
self.num_experts_per_tok,
|
| 1081 |
+
attention_mask,
|
| 1082 |
+
)
|
| 1083 |
+
if labels is not None:
|
| 1084 |
+
loss += self.router_aux_loss_coef * aux_loss.to(loss.device) # make sure to reside in the same device
|
| 1085 |
+
|
| 1086 |
+
return MoeCausalLMOutputWithPast(
|
| 1087 |
+
loss=loss,
|
| 1088 |
+
aux_loss=aux_loss,
|
| 1089 |
+
logits=logits,
|
| 1090 |
+
past_key_values=outputs.past_key_values,
|
| 1091 |
+
hidden_states=outputs.hidden_states,
|
| 1092 |
+
attentions=outputs.attentions,
|
| 1093 |
+
router_logits=outputs.router_logits,
|
| 1094 |
+
)
|
| 1095 |
+
|
| 1096 |
+
|
| 1097 |
+
class K2HorizonForSequenceClassification(GenericForSequenceClassification, K2HorizonPreTrainedModel):
|
| 1098 |
+
pass
|
| 1099 |
+
|
| 1100 |
+
|
| 1101 |
+
class K2HorizonForTokenClassification(GenericForTokenClassification, K2HorizonPreTrainedModel):
|
| 1102 |
+
pass
|
| 1103 |
+
|
| 1104 |
+
|
| 1105 |
+
class K2HorizonForQuestionAnswering(GenericForQuestionAnswering, K2HorizonPreTrainedModel):
|
| 1106 |
+
base_model_prefix = "transformer" # For BC, where `transformer` was used instead of `model`
|
| 1107 |
+
|
| 1108 |
+
|
| 1109 |
+
__all__ = [
|
| 1110 |
+
"K2HorizonForCausalLM",
|
| 1111 |
+
"K2HorizonForQuestionAnswering",
|
| 1112 |
+
"K2HorizonModel",
|
| 1113 |
+
"K2HorizonPreTrainedModel",
|
| 1114 |
+
"K2HorizonForSequenceClassification",
|
| 1115 |
+
"K2HorizonForTokenClassification",
|
| 1116 |
+
]
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:838d767b7c9925ff257feb20eaa4299a8e3cc35bb3d805589c373f51d2cc3cb6
|
| 3 |
+
size 20637260
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<|ifm|begin_of_text|>",
|
| 4 |
+
"clean_up_tokenization_spaces": false,
|
| 5 |
+
"eos_token": "<|ifm|endoftext|>",
|
| 6 |
+
"is_local": true,
|
| 7 |
+
"local_files_only": false,
|
| 8 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 9 |
+
"tokenizer_class": "TokenizersBackend"
|
| 10 |
+
}
|