Text Generation
Transformers
Safetensors
qwen4_exp_text
qwen4-exp
mixture-of-experts
language-model
pretrained
pt
sft
conversational
Instructions to use Modujo-AI/ModujoMoE with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Modujo-AI/ModujoMoE with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Modujo-AI/ModujoMoE") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Modujo-AI/ModujoMoE") model = AutoModelForCausalLM.from_pretrained("Modujo-AI/ModujoMoE", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Modujo-AI/ModujoMoE with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Modujo-AI/ModujoMoE" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Modujo-AI/ModujoMoE", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Modujo-AI/ModujoMoE
- SGLang
How to use Modujo-AI/ModujoMoE with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Modujo-AI/ModujoMoE" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Modujo-AI/ModujoMoE", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Modujo-AI/ModujoMoE" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Modujo-AI/ModujoMoE", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Modujo-AI/ModujoMoE with Docker Model Runner:
docker model run hf.co/Modujo-AI/ModujoMoE
Add Modujo 4B A0.66B PT weights and loading instructions
Browse files- pt/Modujo-4B-A0.66B/README.md +46 -0
- pt/Modujo-4B-A0.66B/__pycache__/qwen4_exp_dense_compat.cpython-312.pyc +0 -0
- pt/Modujo-4B-A0.66B/chat_template.jinja +170 -0
- pt/Modujo-4B-A0.66B/config.json +93 -0
- pt/Modujo-4B-A0.66B/generation_config.json +7 -0
- pt/Modujo-4B-A0.66B/inference.py +20 -0
- pt/Modujo-4B-A0.66B/model.safetensors +3 -0
- pt/Modujo-4B-A0.66B/qwen4_exp_dense_compat.py +62 -0
- pt/Modujo-4B-A0.66B/release.json +15 -0
- pt/Modujo-4B-A0.66B/tested-environment.json +7 -0
- pt/Modujo-4B-A0.66B/tokenizer.json +3 -0
- pt/Modujo-4B-A0.66B/tokenizer_config.json +32 -0
- pt/Modujo-4B-A0.66B/weight-audit.json +9 -0
pt/Modujo-4B-A0.66B/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
+
tags:
|
| 5 |
+
- pretrained
|
| 6 |
+
- pt
|
| 7 |
+
- mixture-of-experts
|
| 8 |
+
- qwen4-exp
|
| 9 |
+
language:
|
| 10 |
+
- zh
|
| 11 |
+
- en
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Modujo 4B A0.66B — PT
|
| 15 |
+
|
| 16 |
+
Approximately 3.96B total and 0.66B active parameters. This is an intermediate **continued-pretraining (PT)** snapshot, not an instruction-tuned assistant and not a completed 100B-token run.
|
| 17 |
+
|
| 18 |
+
## Architecture and lineage
|
| 19 |
+
|
| 20 |
+
28 layers, hidden size 1024, 32 routed experts, top-2,shared expert,tied embeddings. One pass, no trained QSA indexer. Linear-attention and dense-attention layers. Configured maximum positions 32K; current continuation training uses sequences up to 8192.
|
| 21 |
+
|
| 22 |
+
The snapshot comes from the 4B continuation segment on the pt_100b_ecommerce_20261005 corpus. Snapshot provenance and progress are in release.json. The corpus/run's 100B target is a plan, not a claim of tokens consumed by this snapshot. Tensors are stored FP32; FSDP model shards were merged for this release. Training optimizer/RNG files are not included.
|
| 23 |
+
|
| 24 |
+
The SFT directory in this repository was initialized from an earlier PT snapshot; it is not fine-tuned from this later PT release. Do not treat PT and SFT as an equal-step controlled comparison.
|
| 25 |
+
|
| 26 |
+
## Loading and completion
|
| 27 |
+
|
| 28 |
+
Download the subdirectory:
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
from huggingface_hub import snapshot_download
|
| 32 |
+
snapshot_download('Modujo-AI/ModujoMoE',
|
| 33 |
+
allow_patterns=['pt/Modujo-4B-A0.66B/*'],local_dir='./modujo-download')
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
Run in the compatible environment recorded in tested-environment.json. The environment must provide qwen4_exp; the included compatibility helper disables an absent QSA indexer while preserving causal attention.
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
python modujo-download/pt/Modujo-4B-A0.66B/inference.py --device cuda:0 --raw --prompt '中国的首都是' --max-new-tokens 32
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Use raw text completion for base-model inspection. The accompanying native chat template is provided for tokenizer compatibility, not as evidence of instruction tuning. Do not load the repository root without selecting a variant.
|
| 43 |
+
|
| 44 |
+
## Limits
|
| 45 |
+
|
| 46 |
+
Pretraining loss does not establish chat, arithmetic, code or tool reliability. This is a research base snapshot; repetition and instruction failures may occur. Source corpus terms remain applicable. No new blanket license is asserted.
|
pt/Modujo-4B-A0.66B/__pycache__/qwen4_exp_dense_compat.cpython-312.pyc
ADDED
|
Binary file (3.55 kB). View file
|
|
|
pt/Modujo-4B-A0.66B/chat_template.jinja
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- set image_count = namespace(value=0) %}
|
| 2 |
+
{%- set video_count = namespace(value=0) %}
|
| 3 |
+
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 4 |
+
{%- if content is string %}
|
| 5 |
+
{{- content }}
|
| 6 |
+
{%- elif content is iterable and content is not mapping %}
|
| 7 |
+
{%- for item in content %}
|
| 8 |
+
{%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
|
| 9 |
+
{%- if is_system_content %}
|
| 10 |
+
{{- raise_exception('System message cannot contain images.') }}
|
| 11 |
+
{%- endif %}
|
| 12 |
+
{%- if do_vision_count %}
|
| 13 |
+
{%- set image_count.value = image_count.value + 1 %}
|
| 14 |
+
{%- endif %}
|
| 15 |
+
{%- if add_vision_id %}
|
| 16 |
+
{{- 'Picture ' ~ image_count.value ~ ': ' }}
|
| 17 |
+
{%- endif %}
|
| 18 |
+
{{- '<|vision_start|><|image_pad|><|vision_end|>' }}
|
| 19 |
+
{%- elif 'video' in item or item.type == 'video' %}
|
| 20 |
+
{%- if is_system_content %}
|
| 21 |
+
{{- raise_exception('System message cannot contain videos.') }}
|
| 22 |
+
{%- endif %}
|
| 23 |
+
{%- if do_vision_count %}
|
| 24 |
+
{%- set video_count.value = video_count.value + 1 %}
|
| 25 |
+
{%- endif %}
|
| 26 |
+
{%- if add_vision_id %}
|
| 27 |
+
{{- 'Video ' ~ video_count.value ~ ': ' }}
|
| 28 |
+
{%- endif %}
|
| 29 |
+
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
|
| 30 |
+
{%- elif 'text' in item %}
|
| 31 |
+
{{- item.text }}
|
| 32 |
+
{%- else %}
|
| 33 |
+
{{- raise_exception('Unexpected item type in content.') }}
|
| 34 |
+
{%- endif %}
|
| 35 |
+
{%- endfor %}
|
| 36 |
+
{%- elif content is none or content is undefined %}
|
| 37 |
+
{{- '' }}
|
| 38 |
+
{%- else %}
|
| 39 |
+
{{- raise_exception('Unexpected content type.') }}
|
| 40 |
+
{%- endif %}
|
| 41 |
+
{%- endmacro %}
|
| 42 |
+
{%- if not messages %}
|
| 43 |
+
{{- raise_exception('No messages provided.') }}
|
| 44 |
+
{%- endif %}
|
| 45 |
+
{%- set reasoning_instructions = '' %}
|
| 46 |
+
{%- if enable_thinking is undefined or enable_thinking is true %}
|
| 47 |
+
{%- set resolved_reasoning_effort = reasoning_effort|default('xhigh') %}
|
| 48 |
+
{%- if resolved_reasoning_effort not in ('xhigh', 'medium', 'low') %}
|
| 49 |
+
{{- raise_exception('Unexpected reasoning effort ' ~ reasoning_effort ~ '. Supported types are xhigh (default), medium, and low.') }}
|
| 50 |
+
{%- endif %}
|
| 51 |
+
{%- if resolved_reasoning_effort == 'xhigh' %}
|
| 52 |
+
{%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
|
| 53 |
+
{%- elif resolved_reasoning_effort == 'low' %}
|
| 54 |
+
{%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
|
| 55 |
+
{%- endif %}
|
| 56 |
+
{%- endif %}
|
| 57 |
+
{%- if tools and tools is iterable and tools is not mapping %}
|
| 58 |
+
{{- '<|im_start|>system\n' }}
|
| 59 |
+
{%- if reasoning_instructions %}
|
| 60 |
+
{{- reasoning_instructions + '\n\n' }}
|
| 61 |
+
{%- endif %}
|
| 62 |
+
{{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
|
| 63 |
+
{%- for tool in tools %}
|
| 64 |
+
{{- "\n" }}
|
| 65 |
+
{{- tool | tojson }}
|
| 66 |
+
{%- endfor %}
|
| 67 |
+
{{- "\n</tools>" }}
|
| 68 |
+
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
|
| 69 |
+
{%- if messages[0].role == 'system' %}
|
| 70 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 71 |
+
{%- if content %}
|
| 72 |
+
{{- '\n\n' + content }}
|
| 73 |
+
{%- endif %}
|
| 74 |
+
{%- endif %}
|
| 75 |
+
{{- '<|im_end|>\n' }}
|
| 76 |
+
{%- else %}
|
| 77 |
+
{%- if messages[0].role == 'system' %}
|
| 78 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 79 |
+
{%- if content %}
|
| 80 |
+
{{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' }}
|
| 81 |
+
{%- elif reasoning_instructions %}
|
| 82 |
+
{{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
|
| 83 |
+
{%- endif %}
|
| 84 |
+
{%- elif reasoning_instructions %}
|
| 85 |
+
{{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
|
| 86 |
+
{%- endif %}
|
| 87 |
+
{%- endif %}
|
| 88 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 89 |
+
{%- for message in messages[::-1] %}
|
| 90 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 91 |
+
{%- if ns.multi_step_tool and message.role == "user" %}
|
| 92 |
+
{%- set content = render_content(message.content, false)|trim %}
|
| 93 |
+
{%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
|
| 94 |
+
{%- set ns.multi_step_tool = false %}
|
| 95 |
+
{%- set ns.last_query_index = index %}
|
| 96 |
+
{%- endif %}
|
| 97 |
+
{%- endif %}
|
| 98 |
+
{%- endfor %}
|
| 99 |
+
{%- if ns.multi_step_tool %}
|
| 100 |
+
{{- raise_exception('No user query found in messages.') }}
|
| 101 |
+
{%- endif %}
|
| 102 |
+
{%- for message in messages %}
|
| 103 |
+
{%- set content = render_content(message.content, true)|trim %}
|
| 104 |
+
{%- if message.role == "system" %}
|
| 105 |
+
{%- if not loop.first %}
|
| 106 |
+
{{- raise_exception('System message must be at the beginning.') }}
|
| 107 |
+
{%- endif %}
|
| 108 |
+
{%- elif message.role == "user" %}
|
| 109 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 110 |
+
{%- elif message.role == "assistant" %}
|
| 111 |
+
{%- set reasoning_content = '' %}
|
| 112 |
+
{%- if message.reasoning_content is string %}
|
| 113 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 114 |
+
{%- endif %}
|
| 115 |
+
{%- set reasoning_content = reasoning_content|trim %}
|
| 116 |
+
{%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index %}
|
| 117 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
|
| 118 |
+
{%- else %}
|
| 119 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 120 |
+
{%- endif %}
|
| 121 |
+
{%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
|
| 122 |
+
{%- for tool_call in message.tool_calls %}
|
| 123 |
+
{%- if tool_call.function is defined %}
|
| 124 |
+
{%- set tool_call = tool_call.function %}
|
| 125 |
+
{%- endif %}
|
| 126 |
+
{%- if loop.first %}
|
| 127 |
+
{%- if content|trim %}
|
| 128 |
+
{{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 129 |
+
{%- else %}
|
| 130 |
+
{{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 131 |
+
{%- endif %}
|
| 132 |
+
{%- else %}
|
| 133 |
+
{{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 134 |
+
{%- endif %}
|
| 135 |
+
{%- if tool_call.arguments is defined and tool_call.arguments != '' %}
|
| 136 |
+
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 137 |
+
{{- '<parameter=' + args_name + '>\n' }}
|
| 138 |
+
{%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
|
| 139 |
+
{{- args_value }}
|
| 140 |
+
{{- '\n</parameter>\n' }}
|
| 141 |
+
{%- endfor %}
|
| 142 |
+
{%- endif %}
|
| 143 |
+
{{- '</function>\n</tool_call>' }}
|
| 144 |
+
{%- endfor %}
|
| 145 |
+
{%- endif %}
|
| 146 |
+
{{- '<|im_end|>\n' }}
|
| 147 |
+
{%- elif message.role == "tool" %}
|
| 148 |
+
{%- if loop.previtem and loop.previtem.role != "tool" %}
|
| 149 |
+
{{- '<|im_start|>user' }}
|
| 150 |
+
{%- endif %}
|
| 151 |
+
{{- '\n<tool_response>\n' }}
|
| 152 |
+
{{- content }}
|
| 153 |
+
{{- '\n</tool_response>' }}
|
| 154 |
+
{%- if not loop.last and loop.nextitem.role != "tool" %}
|
| 155 |
+
{{- '<|im_end|>\n' }}
|
| 156 |
+
{%- elif loop.last %}
|
| 157 |
+
{{- '<|im_end|>\n' }}
|
| 158 |
+
{%- endif %}
|
| 159 |
+
{%- else %}
|
| 160 |
+
{{- raise_exception('Unexpected message role.') }}
|
| 161 |
+
{%- endif %}
|
| 162 |
+
{%- endfor %}
|
| 163 |
+
{%- if add_generation_prompt %}
|
| 164 |
+
{{- '<|im_start|>assistant\n' }}
|
| 165 |
+
{%- if enable_thinking is defined and enable_thinking is false %}
|
| 166 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 167 |
+
{%- else %}
|
| 168 |
+
{{- '<think>\n' }}
|
| 169 |
+
{%- endif %}
|
| 170 |
+
{%- endif %}
|
pt/Modujo-4B-A0.66B/config.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Qwen4ExpForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 248044,
|
| 8 |
+
"dtype": "float32",
|
| 9 |
+
"eos_token_id": 248046,
|
| 10 |
+
"experts_impl": "grouped_mm",
|
| 11 |
+
"hc_count": 4,
|
| 12 |
+
"hc_lowrank": 128,
|
| 13 |
+
"head_dim": 64,
|
| 14 |
+
"heads_per_ngram": 6,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"hidden_size": 1024,
|
| 17 |
+
"indexer_budget": null,
|
| 18 |
+
"indexer_compress_ratio": null,
|
| 19 |
+
"indexer_head_dim": null,
|
| 20 |
+
"indexer_kv_heads": null,
|
| 21 |
+
"indexer_n_heads": null,
|
| 22 |
+
"initializer_range": 0.02,
|
| 23 |
+
"layer_types": [
|
| 24 |
+
"linear_attention",
|
| 25 |
+
"linear_attention",
|
| 26 |
+
"linear_attention",
|
| 27 |
+
"qwen_sparse_attention",
|
| 28 |
+
"linear_attention",
|
| 29 |
+
"linear_attention",
|
| 30 |
+
"linear_attention",
|
| 31 |
+
"qwen_sparse_attention",
|
| 32 |
+
"linear_attention",
|
| 33 |
+
"linear_attention",
|
| 34 |
+
"linear_attention",
|
| 35 |
+
"qwen_sparse_attention",
|
| 36 |
+
"linear_attention",
|
| 37 |
+
"linear_attention",
|
| 38 |
+
"linear_attention",
|
| 39 |
+
"qwen_sparse_attention",
|
| 40 |
+
"linear_attention",
|
| 41 |
+
"linear_attention",
|
| 42 |
+
"linear_attention",
|
| 43 |
+
"qwen_sparse_attention",
|
| 44 |
+
"linear_attention",
|
| 45 |
+
"linear_attention",
|
| 46 |
+
"linear_attention",
|
| 47 |
+
"qwen_sparse_attention",
|
| 48 |
+
"linear_attention",
|
| 49 |
+
"linear_attention",
|
| 50 |
+
"linear_attention",
|
| 51 |
+
"qwen_sparse_attention"
|
| 52 |
+
],
|
| 53 |
+
"linear_conv_kernel_dim": 4,
|
| 54 |
+
"linear_key_head_dim": 64,
|
| 55 |
+
"linear_num_key_heads": 8,
|
| 56 |
+
"linear_num_value_heads": 16,
|
| 57 |
+
"linear_value_head_dim": 64,
|
| 58 |
+
"loop_repeats": 1,
|
| 59 |
+
"make_ngram_vocab_size_divisible_by": 128,
|
| 60 |
+
"max_position_embeddings": 32768,
|
| 61 |
+
"model_type": "qwen4_exp_text",
|
| 62 |
+
"modujo_loop_repeats": 1,
|
| 63 |
+
"moe_intermediate_size": 1280,
|
| 64 |
+
"ngram_size": 3,
|
| 65 |
+
"ngram_vocab_size_base": 144128,
|
| 66 |
+
"norm_topk_prob": true,
|
| 67 |
+
"num_attention_heads": 16,
|
| 68 |
+
"num_experts": 32,
|
| 69 |
+
"num_experts_per_tok": 2,
|
| 70 |
+
"num_hidden_layers": 28,
|
| 71 |
+
"num_key_value_heads": 2,
|
| 72 |
+
"number_of_conv_states": 3,
|
| 73 |
+
"output_gate_type": "sigmoid",
|
| 74 |
+
"output_router_logits": true,
|
| 75 |
+
"pad_token_id": 248044,
|
| 76 |
+
"ple_conv_kernel_size": 4,
|
| 77 |
+
"ple_embed_dim": 1024,
|
| 78 |
+
"ple_layer_ids": [],
|
| 79 |
+
"rms_norm_eps": 1e-06,
|
| 80 |
+
"rope_parameters": {
|
| 81 |
+
"partial_rotary_factor": 0.25,
|
| 82 |
+
"rope_theta": 10000000,
|
| 83 |
+
"rope_type": "default"
|
| 84 |
+
},
|
| 85 |
+
"router_aux_loss_coef": 0.001,
|
| 86 |
+
"seed": 1234,
|
| 87 |
+
"shared_expert_intermediate_size": 128,
|
| 88 |
+
"split_ngram_parts": 128,
|
| 89 |
+
"tie_word_embeddings": true,
|
| 90 |
+
"transformers_version": "5.16.1",
|
| 91 |
+
"use_cache": true,
|
| 92 |
+
"vocab_size": 248320
|
| 93 |
+
}
|
pt/Modujo-4B-A0.66B/generation_config.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 248044,
|
| 3 |
+
"eos_token_id": 248046,
|
| 4 |
+
"pad_token_id": 248044,
|
| 5 |
+
"transformers_version": "5.16.1",
|
| 6 |
+
"use_cache": true
|
| 7 |
+
}
|
pt/Modujo-4B-A0.66B/inference.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import torch
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM
|
| 5 |
+
from qwen4_exp_dense_compat import enable_dense_qwen4_exp_attention
|
| 6 |
+
|
| 7 |
+
p=argparse.ArgumentParser();p.add_argument('--raw',action='store_true');p.add_argument('--prompt',default='What is the capital of France? Answer in one sentence.');p.add_argument('--device',default='cuda:0');p.add_argument('--max-new-tokens',type=int,default=192);a=p.parse_args()
|
| 8 |
+
enable_dense_qwen4_exp_attention()
|
| 9 |
+
if a.device=='cpu':
|
| 10 |
+
from transformers.models.qwen4_exp import modeling_qwen4_exp as modeling
|
| 11 |
+
for name in ['causal_conv1d_fn','causal_conv1d_update','torch_chunk_gated_delta_rule','torch_recurrent_gated_delta_rule']:
|
| 12 |
+
f=getattr(modeling,name);setattr(modeling,name,getattr(f,'__wrapped__',f))
|
| 13 |
+
torch.set_num_threads(8)
|
| 14 |
+
base=Path(__file__).resolve().parent
|
| 15 |
+
t=AutoTokenizer.from_pretrained(base,local_files_only=True);c=AutoConfig.from_pretrained(base,local_files_only=True);c.experts_impl='eager';c.output_router_logits=False
|
| 16 |
+
m=AutoModelForCausalLM.from_pretrained(base,config=c,dtype=torch.bfloat16,attn_implementation='eager',device_map=a.device,local_files_only=True).eval()
|
| 17 |
+
s=a.prompt if a.raw else t.apply_chat_template([{'role':'user','content':a.prompt}],tokenize=False,add_generation_prompt=True,enable_thinking=False);inputs=t(s,return_tensors='pt').to(a.device)
|
| 18 |
+
with torch.inference_mode():
|
| 19 |
+
ids=m.generate(**inputs,max_new_tokens=a.max_new_tokens,do_sample=False,use_cache=True,logits_to_keep=1,pad_token_id=t.pad_token_id)[0,inputs.input_ids.shape[1]:]
|
| 20 |
+
print(t.decode(ids,skip_special_tokens=True))
|
pt/Modujo-4B-A0.66B/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:52ff09415352b5baaf7270c94bec670e9fa9a661731718b8ad5e7f506ea72c68
|
| 3 |
+
size 16869879192
|
pt/Modujo-4B-A0.66B/qwen4_exp_dense_compat.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Compatibility support for pre-QSA dense Qwen4-Exp checkpoints.
|
| 2 |
+
|
| 3 |
+
Transformers 5.16 accepts ``None`` QSA fields in the configuration but still
|
| 4 |
+
constructs and calls the QSA indexer. A pre-QSA checkpoint needs the same
|
| 5 |
+
attention module and parameter names, with the indexer absent and the ordinary
|
| 6 |
+
causal mask passed directly to the core attention operation.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
_PATCHED = False
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def qsa_is_enabled(config: Any) -> bool:
|
| 20 |
+
fields = (
|
| 21 |
+
"indexer_n_heads",
|
| 22 |
+
"indexer_kv_heads",
|
| 23 |
+
"indexer_head_dim",
|
| 24 |
+
"indexer_budget",
|
| 25 |
+
"indexer_compress_ratio",
|
| 26 |
+
)
|
| 27 |
+
values = [getattr(config, name, None) for name in fields]
|
| 28 |
+
if any(value is None for value in values) and any(value is not None for value in values):
|
| 29 |
+
raise ValueError("QSA indexer fields must either all be set or all be None")
|
| 30 |
+
return all(value is not None for value in values)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def enable_dense_qwen4_exp_attention() -> None:
|
| 34 |
+
"""Make null-indexer Qwen4-Exp attention execute as dense attention."""
|
| 35 |
+
global _PATCHED
|
| 36 |
+
if _PATCHED:
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
from transformers.models.qwen4_exp import modeling_qwen4_exp as modeling
|
| 40 |
+
|
| 41 |
+
original_init = modeling.Qwen4ExpTextQSAIndexer.__init__
|
| 42 |
+
original_forward = modeling.Qwen4ExpTextQSAIndexer.forward
|
| 43 |
+
|
| 44 |
+
def patched_init(self, config, layer_idx):
|
| 45 |
+
if qsa_is_enabled(config):
|
| 46 |
+
original_init(self, config, layer_idx)
|
| 47 |
+
self.qsa_enabled = True
|
| 48 |
+
else:
|
| 49 |
+
torch.nn.Module.__init__(self)
|
| 50 |
+
self.layer_idx = layer_idx
|
| 51 |
+
self.qsa_enabled = False
|
| 52 |
+
|
| 53 |
+
def patched_forward(self, hidden_states, position_embeddings, attention_mask, past_key_values):
|
| 54 |
+
if self.qsa_enabled:
|
| 55 |
+
return original_forward(self, hidden_states, position_embeddings, attention_mask, past_key_values)
|
| 56 |
+
if attention_mask.dtype == torch.bool:
|
| 57 |
+
return torch.ones_like(attention_mask, dtype=torch.bool)
|
| 58 |
+
return torch.zeros_like(attention_mask)
|
| 59 |
+
|
| 60 |
+
modeling.Qwen4ExpTextQSAIndexer.__init__ = patched_init
|
| 61 |
+
modeling.Qwen4ExpTextQSAIndexer.forward = patched_forward
|
| 62 |
+
_PATCHED = True
|
pt/Modujo-4B-A0.66B/release.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"repository": "Modujo-AI/ModujoMoE",
|
| 3 |
+
"subdirectory": "pt/Modujo-4B-A0.66B",
|
| 4 |
+
"stage": "continued pretraining",
|
| 5 |
+
"snapshot_step": 19500,
|
| 6 |
+
"planned_segment_steps": 217894,
|
| 7 |
+
"segment_epoch": 0.0894932616163401,
|
| 8 |
+
"complete_training": false,
|
| 9 |
+
"total_parameters_approx": 3963169632,
|
| 10 |
+
"active_parameters_approx": 660155232,
|
| 11 |
+
"stored_dtype": "float32",
|
| 12 |
+
"note": "This PT is a later continued-pretraining snapshot. The uploaded SFT was initialized from an earlier PT snapshot, not from this PT release.",
|
| 13 |
+
"source_run": "modujo-4b-new-pt-20261005/segment-001",
|
| 14 |
+
"source_parent_step": 500
|
| 15 |
+
}
|
pt/Modujo-4B-A0.66B/tested-environment.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"torch": "2.13.0+cu130",
|
| 3 |
+
"transformers": "5.16.1",
|
| 4 |
+
"accelerate": "1.15.0",
|
| 5 |
+
"huggingface_hub": "1.31.0",
|
| 6 |
+
"safetensors": "0.8.0"
|
| 7 |
+
}
|
pt/Modujo-4B-A0.66B/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:06b9509352d2af50381ab2247e083b80d32d5c0aba91c272ca9ff729b6a0e523
|
| 3 |
+
size 19989325
|
pt/Modujo-4B-A0.66B/tokenizer_config.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"audio_bos_token": "<|audio_start|>",
|
| 4 |
+
"audio_eos_token": "<|audio_end|>",
|
| 5 |
+
"audio_token": "<|audio_pad|>",
|
| 6 |
+
"backend": "tokenizers",
|
| 7 |
+
"bos_token": null,
|
| 8 |
+
"clean_up_tokenization_spaces": false,
|
| 9 |
+
"eos_token": "<|im_end|>",
|
| 10 |
+
"errors": "replace",
|
| 11 |
+
"image_token": "<|image_pad|>",
|
| 12 |
+
"is_local": true,
|
| 13 |
+
"local_files_only": true,
|
| 14 |
+
"model_max_length": 262144,
|
| 15 |
+
"model_specific_special_tokens": {
|
| 16 |
+
"audio_bos_token": "<|audio_start|>",
|
| 17 |
+
"audio_eos_token": "<|audio_end|>",
|
| 18 |
+
"audio_token": "<|audio_pad|>",
|
| 19 |
+
"image_token": "<|image_pad|>",
|
| 20 |
+
"video_token": "<|video_pad|>",
|
| 21 |
+
"vision_bos_token": "<|vision_start|>",
|
| 22 |
+
"vision_eos_token": "<|vision_end|>"
|
| 23 |
+
},
|
| 24 |
+
"pad_token": "<|endoftext|>",
|
| 25 |
+
"pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
|
| 26 |
+
"split_special_tokens": false,
|
| 27 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 28 |
+
"unk_token": null,
|
| 29 |
+
"video_token": "<|video_pad|>",
|
| 30 |
+
"vision_bos_token": "<|vision_start|>",
|
| 31 |
+
"vision_eos_token": "<|vision_end|>"
|
| 32 |
+
}
|
pt/Modujo-4B-A0.66B/weight-audit.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"all_finite": true,
|
| 3 |
+
"dtypes": {
|
| 4 |
+
"torch.float32": 656
|
| 5 |
+
},
|
| 6 |
+
"serialized_numel": 4217449312,
|
| 7 |
+
"bytes": 16869879192,
|
| 8 |
+
"sha256": "52ff09415352b5baaf7270c94bec670e9fa9a661731718b8ad5e7f506ea72c68"
|
| 9 |
+
}
|