Instructions to use trl-internal-testing/tiny-Lfm2ForCausalLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use trl-internal-testing/tiny-Lfm2ForCausalLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="trl-internal-testing/tiny-Lfm2ForCausalLM") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("trl-internal-testing/tiny-Lfm2ForCausalLM") model = AutoModelForCausalLM.from_pretrained("trl-internal-testing/tiny-Lfm2ForCausalLM", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use trl-internal-testing/tiny-Lfm2ForCausalLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "trl-internal-testing/tiny-Lfm2ForCausalLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "trl-internal-testing/tiny-Lfm2ForCausalLM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/trl-internal-testing/tiny-Lfm2ForCausalLM
- SGLang
How to use trl-internal-testing/tiny-Lfm2ForCausalLM 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 "trl-internal-testing/tiny-Lfm2ForCausalLM" \ --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": "trl-internal-testing/tiny-Lfm2ForCausalLM", "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 "trl-internal-testing/tiny-Lfm2ForCausalLM" \ --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": "trl-internal-testing/tiny-Lfm2ForCausalLM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use trl-internal-testing/tiny-Lfm2ForCausalLM with Docker Model Runner:
docker model run hf.co/trl-internal-testing/tiny-Lfm2ForCausalLM
Upload Lfm2ForCausalLM
#1
by albertvillanova HF Staff - opened
- chat_template.jinja +37 -2
- config.json +13 -1
- model.safetensors +1 -1
chat_template.jinja
CHANGED
|
@@ -1,4 +1,31 @@
|
|
| 1 |
{{- bos_token -}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
{%- set system_prompt = "" -%}
|
| 3 |
{%- set ns = namespace(system_prompt="") -%}
|
| 4 |
{%- if messages[0]["role"] == "system" -%}
|
|
@@ -23,14 +50,22 @@
|
|
| 23 |
{%- endif -%}
|
| 24 |
{%- for message in messages -%}
|
| 25 |
{{- "<|im_start|>" + message["role"] + "\n" -}}
|
| 26 |
-
{%- set content = message
|
| 27 |
{%- if content is not string -%}
|
| 28 |
{%- set content = content | tojson -%}
|
| 29 |
{%- endif -%}
|
| 30 |
{%- if message["role"] == "tool" -%}
|
| 31 |
{%- set content = "<|tool_response_start|>" + content + "<|tool_response_end|>" -%}
|
| 32 |
{%- endif -%}
|
| 33 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
{%- endfor -%}
|
| 35 |
{%- if add_generation_prompt -%}
|
| 36 |
{{- "<|im_start|>assistant\n" -}}
|
|
|
|
| 1 |
{{- bos_token -}}
|
| 2 |
+
{%- macro format_arg_value(arg_value) -%}
|
| 3 |
+
{%- if arg_value is string -%}
|
| 4 |
+
{{- "'" + (arg_value | replace("\\", "\\\\") | replace("'", "\\'") | replace("\n", "\\n") | replace("\r", "\\r")) + "'" -}}
|
| 5 |
+
{%- elif arg_value is mapping or arg_value is iterable -%}
|
| 6 |
+
{{- arg_value | tojson -}}
|
| 7 |
+
{%- else -%}
|
| 8 |
+
{{- arg_value | string -}}
|
| 9 |
+
{%- endif -%}
|
| 10 |
+
{%- endmacro -%}
|
| 11 |
+
{%- macro render_tool_calls(tool_calls) -%}
|
| 12 |
+
{%- set tool_calls_ns = namespace(tool_calls=[]) -%}
|
| 13 |
+
{%- for tool_call in tool_calls -%}
|
| 14 |
+
{%- set func = tool_call["function"] if "function" in tool_call else tool_call -%}
|
| 15 |
+
{%- set func_name = func["name"] -%}
|
| 16 |
+
{%- set func_args = func.get("arguments") -%}
|
| 17 |
+
{%- set args_ns = namespace(arg_strings=[]) -%}
|
| 18 |
+
{%- if func_args is mapping -%}
|
| 19 |
+
{%- for arg_name, arg_value in func_args.items() -%}
|
| 20 |
+
{%- set args_ns.arg_strings = args_ns.arg_strings + [arg_name + "=" + format_arg_value(arg_value)] -%}
|
| 21 |
+
{%- endfor -%}
|
| 22 |
+
{%- elif func_args is string and (func_args | trim) not in ["", "{}", "null"] -%}
|
| 23 |
+
{{- raise_exception("Tool call arguments must be a mapping, got a JSON-encoded string: parse arguments with json.loads() before applying the chat template") -}}
|
| 24 |
+
{%- endif -%}
|
| 25 |
+
{%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [func_name + "(" + (args_ns.arg_strings | join(", ")) + ")"] -%}
|
| 26 |
+
{%- endfor -%}
|
| 27 |
+
{{- "<|tool_call_start|>[" + (tool_calls_ns.tool_calls | join(", ")) + "]<|tool_call_end|>" -}}
|
| 28 |
+
{%- endmacro -%}
|
| 29 |
{%- set system_prompt = "" -%}
|
| 30 |
{%- set ns = namespace(system_prompt="") -%}
|
| 31 |
{%- if messages[0]["role"] == "system" -%}
|
|
|
|
| 50 |
{%- endif -%}
|
| 51 |
{%- for message in messages -%}
|
| 52 |
{{- "<|im_start|>" + message["role"] + "\n" -}}
|
| 53 |
+
{%- set content = message.get("content") -%}
|
| 54 |
{%- if content is not string -%}
|
| 55 |
{%- set content = content | tojson -%}
|
| 56 |
{%- endif -%}
|
| 57 |
{%- if message["role"] == "tool" -%}
|
| 58 |
{%- set content = "<|tool_response_start|>" + content + "<|tool_response_end|>" -%}
|
| 59 |
{%- endif -%}
|
| 60 |
+
{%- if message["role"] == "assistant" and message.get("tool_calls") -%}
|
| 61 |
+
{%- if content and content != "null" -%}
|
| 62 |
+
{{- content -}}
|
| 63 |
+
{%- endif -%}
|
| 64 |
+
{{- render_tool_calls(message["tool_calls"]) -}}
|
| 65 |
+
{{- "<|im_end|>\n" -}}
|
| 66 |
+
{%- else -%}
|
| 67 |
+
{{- content + "<|im_end|>\n" -}}
|
| 68 |
+
{%- endif -%}
|
| 69 |
{%- endfor -%}
|
| 70 |
{%- if add_generation_prompt -%}
|
| 71 |
{{- "<|im_start|>assistant\n" -}}
|
config.json
CHANGED
|
@@ -3,11 +3,21 @@
|
|
| 3 |
"Lfm2ForCausalLM"
|
| 4 |
],
|
| 5 |
"block_auto_adjust_ff_dim": true,
|
|
|
|
|
|
|
| 6 |
"block_ffn_dim_multiplier": 1.0,
|
|
|
|
| 7 |
"block_multiple_of": 8,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
"bos_token_id": 1,
|
| 9 |
"conv_L_cache": 3,
|
| 10 |
"conv_bias": false,
|
|
|
|
|
|
|
|
|
|
| 11 |
"dtype": "bfloat16",
|
| 12 |
"eos_token_id": 7,
|
| 13 |
"hidden_size": 8,
|
|
@@ -21,11 +31,13 @@
|
|
| 21 |
"model_type": "lfm2",
|
| 22 |
"norm_eps": 1e-05,
|
| 23 |
"num_attention_heads": 4,
|
|
|
|
| 24 |
"num_hidden_layers": 2,
|
| 25 |
"num_key_value_heads": 2,
|
| 26 |
"pad_token_id": 0,
|
| 27 |
"rope_theta": 1000000.0,
|
| 28 |
"transformers_version": "4.56.2",
|
| 29 |
-
"use_cache":
|
|
|
|
| 30 |
"vocab_size": 65536
|
| 31 |
}
|
|
|
|
| 3 |
"Lfm2ForCausalLM"
|
| 4 |
],
|
| 5 |
"block_auto_adjust_ff_dim": true,
|
| 6 |
+
"block_dim": 8,
|
| 7 |
+
"block_ff_dim": 32,
|
| 8 |
"block_ffn_dim_multiplier": 1.0,
|
| 9 |
+
"block_mlp_init_scale": 1.0,
|
| 10 |
"block_multiple_of": 8,
|
| 11 |
+
"block_norm_eps": 1e-05,
|
| 12 |
+
"block_out_init_scale": 1.0,
|
| 13 |
+
"block_use_swiglu": true,
|
| 14 |
+
"block_use_xavier_init": true,
|
| 15 |
"bos_token_id": 1,
|
| 16 |
"conv_L_cache": 3,
|
| 17 |
"conv_bias": false,
|
| 18 |
+
"conv_dim": 8,
|
| 19 |
+
"conv_dim_out": 8,
|
| 20 |
+
"conv_use_xavier_init": true,
|
| 21 |
"dtype": "bfloat16",
|
| 22 |
"eos_token_id": 7,
|
| 23 |
"hidden_size": 8,
|
|
|
|
| 31 |
"model_type": "lfm2",
|
| 32 |
"norm_eps": 1e-05,
|
| 33 |
"num_attention_heads": 4,
|
| 34 |
+
"num_heads": 4,
|
| 35 |
"num_hidden_layers": 2,
|
| 36 |
"num_key_value_heads": 2,
|
| 37 |
"pad_token_id": 0,
|
| 38 |
"rope_theta": 1000000.0,
|
| 39 |
"transformers_version": "4.56.2",
|
| 40 |
+
"use_cache": true,
|
| 41 |
+
"use_pos_enc": true,
|
| 42 |
"vocab_size": 65536
|
| 43 |
}
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 1054096
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7cf8031f34b33a591cb956c0ee9561e2dcad9d8bc960a2f896af332ce4e67183
|
| 3 |
size 1054096
|