Text Generation
Transformers
Safetensors
English
spark2_5
uncensored
abliterated
spark
biprojection
norm-preserving
conversational
custom_code
Instructions to use InfinimindCreations/Spark-X2.5-4B-uncensored with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use InfinimindCreations/Spark-X2.5-4B-uncensored with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="InfinimindCreations/Spark-X2.5-4B-uncensored", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("InfinimindCreations/Spark-X2.5-4B-uncensored", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use InfinimindCreations/Spark-X2.5-4B-uncensored with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "InfinimindCreations/Spark-X2.5-4B-uncensored" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "InfinimindCreations/Spark-X2.5-4B-uncensored", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/InfinimindCreations/Spark-X2.5-4B-uncensored
- SGLang
How to use InfinimindCreations/Spark-X2.5-4B-uncensored 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 "InfinimindCreations/Spark-X2.5-4B-uncensored" \ --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": "InfinimindCreations/Spark-X2.5-4B-uncensored", "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 "InfinimindCreations/Spark-X2.5-4B-uncensored" \ --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": "InfinimindCreations/Spark-X2.5-4B-uncensored", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use InfinimindCreations/Spark-X2.5-4B-uncensored with Docker Model Runner:
docker model run hf.co/InfinimindCreations/Spark-X2.5-4B-uncensored
Upload chat_template.jinja with huggingface_hub
Browse files- chat_template.jinja +110 -0
chat_template.jinja
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{#- 0826版本 -#}
|
| 2 |
+
{%- if not messages %}
|
| 3 |
+
{{- raise_exception('No messages provided.') }}
|
| 4 |
+
{%- endif %}
|
| 5 |
+
{%- set enable_thinking = enable_thinking | default(true) %}
|
| 6 |
+
|
| 7 |
+
{#- Render a string or a list of text blocks. -#}
|
| 8 |
+
{%- macro render_content(content, context_name) %}
|
| 9 |
+
{%- if content is string %}
|
| 10 |
+
{{- content }}
|
| 11 |
+
{%- elif content is none or content is undefined %}
|
| 12 |
+
{{- '' }}
|
| 13 |
+
{%- elif content is iterable and content is not mapping %}
|
| 14 |
+
{%- for block in content %}
|
| 15 |
+
{%- if block.type == 'text' %}
|
| 16 |
+
{{- block.text }}
|
| 17 |
+
{%- else %}
|
| 18 |
+
{{- raise_exception('Unsupported ' ~ context_name ~ ' content block type: ' ~ (block.type | string)) }}
|
| 19 |
+
{%- endif %}
|
| 20 |
+
{%- endfor %}
|
| 21 |
+
{%- else %}
|
| 22 |
+
{{- raise_exception(context_name ~ ' content must be a string or a list of text blocks') }}
|
| 23 |
+
{%- endif %}
|
| 24 |
+
{%- endmacro %}
|
| 25 |
+
|
| 26 |
+
{#- Default system prompt -#}
|
| 27 |
+
{%- set default_system = "you are a helpful assistant." %}
|
| 28 |
+
|
| 29 |
+
{#- The first message-level system is placed in the initial system block. -#}
|
| 30 |
+
{%- set ns = namespace(initial_system='') %}
|
| 31 |
+
{%- if messages[0].role == "system" %}
|
| 32 |
+
{%- set ns.initial_system = render_content(messages[0].content, 'system') %}
|
| 33 |
+
{%- endif %}
|
| 34 |
+
|
| 35 |
+
{#- System block -#}
|
| 36 |
+
{{- '<|start▁of▁sentence|><|System|>' + '\n' + default_system }}
|
| 37 |
+
{%- if tools %}
|
| 38 |
+
{{- '## Tools' + '\n' + 'You have access to the following functions:' + '\n' + '<tools>' }}
|
| 39 |
+
{%- for tool in tools %}
|
| 40 |
+
{{- '\n' + tool.function | tojson}}
|
| 41 |
+
{%- endfor %}
|
| 42 |
+
{{- '\n' + '</tools>' }}
|
| 43 |
+
{%- endif %}
|
| 44 |
+
{%- if ns.initial_system %}
|
| 45 |
+
{{- '\n\n' + ns.initial_system }}
|
| 46 |
+
{%- endif %}
|
| 47 |
+
{{- '<|end▁of▁sentence|>'}}
|
| 48 |
+
|
| 49 |
+
{#- Conversation turns -#}
|
| 50 |
+
{%- for message in messages %}
|
| 51 |
+
{%- if message.role == "system" %}
|
| 52 |
+
{#- The first system message was consumed by the initial block. -#}
|
| 53 |
+
{%- if not loop.first %}
|
| 54 |
+
{{- '<|start▁of▁sentence|><|System|>\n' + render_content(message.content, 'system') + '<|end▁of▁sentence|>' }}
|
| 55 |
+
{%- endif %}
|
| 56 |
+
{%- elif message.role == "user" %}
|
| 57 |
+
{{- '<|start▁of▁sentence|><|User|>' + render_content(message.content, 'user') + '<|end▁of▁sentence|>' }}
|
| 58 |
+
{%- elif message.role == "assistant" %}
|
| 59 |
+
{%- set assistant_content = render_content(message.content, 'assistant') %}
|
| 60 |
+
{%- if message.reasoning_content is defined and message.reasoning_content %}
|
| 61 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 62 |
+
{%- else %}
|
| 63 |
+
{%- set reasoning_content = '' %}
|
| 64 |
+
{%- endif %}
|
| 65 |
+
{{- '<|start▁of▁sentence|><|Bot|>'}}
|
| 66 |
+
{%- if reasoning_content %}
|
| 67 |
+
{{- '<think>' + reasoning_content + '</think>'}}
|
| 68 |
+
{%- else %}
|
| 69 |
+
{{- '</think>' }}
|
| 70 |
+
{%- endif %}
|
| 71 |
+
{%- if assistant_content %}
|
| 72 |
+
{{- assistant_content }}
|
| 73 |
+
{%- endif %}
|
| 74 |
+
{%- if message.tool_calls is defined and message.tool_calls is not none %}
|
| 75 |
+
{%- for tool_call in message.tool_calls %}
|
| 76 |
+
{%- if tool_call.function.arguments is not mapping %}
|
| 77 |
+
{{- raise_exception('tool_call.function.arguments must be a dictionary; normalize JSON strings before apply_chat_template') }}
|
| 78 |
+
{%- endif %}
|
| 79 |
+
{%- set args = tool_call.function.arguments %}
|
| 80 |
+
{{- '<tool_call>' + tool_call.function.name }}
|
| 81 |
+
{%- for k, v in args.items() %}
|
| 82 |
+
{{- '<arg_key>' ~ k ~ '</arg_key><arg_value>' ~ (v if v is string else v | tojson) ~ '</arg_value>' }}
|
| 83 |
+
{%- endfor %}
|
| 84 |
+
{{- '</tool_call>' }}
|
| 85 |
+
{%- endfor %}
|
| 86 |
+
{%- endif %}
|
| 87 |
+
{{- '<|end▁of▁sentence|>' }}
|
| 88 |
+
{%- elif message.role == "tool" %}
|
| 89 |
+
{%- if loop.previtem is undefined or loop.previtem.role != "tool" %}
|
| 90 |
+
{{- '<|start▁of▁sentence|><|Tool|>' }}
|
| 91 |
+
{%- endif %}
|
| 92 |
+
{{- '<tool_response>' ~ message.content ~ '</tool_response>' }}
|
| 93 |
+
{%- if loop.nextitem is undefined or loop.nextitem.role != "tool" %}
|
| 94 |
+
{{- '<|end▁of▁sentence|>' }}
|
| 95 |
+
{%- endif %}
|
| 96 |
+
{%- else %}
|
| 97 |
+
{{- raise_exception('Unsupported message role: ' ~ message.role) }}
|
| 98 |
+
{%- endif %}
|
| 99 |
+
{%- endfor %}
|
| 100 |
+
|
| 101 |
+
{#- Generation prompt -#}
|
| 102 |
+
{%- if add_generation_prompt %}
|
| 103 |
+
{{- '<|start▁of▁sentence|><|Bot|>' }}
|
| 104 |
+
{%- if enable_thinking is defined and enable_thinking %}
|
| 105 |
+
{{- '<think>' }}
|
| 106 |
+
{%- endif %}
|
| 107 |
+
{%- if enable_thinking is defined and not enable_thinking %}
|
| 108 |
+
{{- '</think>' }}
|
| 109 |
+
{%- endif %}
|
| 110 |
+
{%- endif %}
|