hauser commited on
Commit
f260793
·
verified ·
1 Parent(s): 130a4d5

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: lfm1.0
4
+ license_link: https://huggingface.co/LiquidAI/LFM2.5-230M/blob/main/LICENSE
5
+ base_model: LiquidAI/LFM2.5-230M
6
+ tags:
7
+ - lfm2
8
+ - lfm2.5
9
+ - liquid
10
+ - code
11
+ - math
12
+ - fine-tune
13
+ language:
14
+ - en
15
+ pipeline_tag: text-generation
16
+ ---
17
+
18
+ # LFM2.5-230M-Code-Math
19
+
20
+ A fine-tune of [LiquidAI/LFM2.5-230M](https://huggingface.co/LiquidAI/LFM2.5-230M) (the instruct-tuned model, **not** the base checkpoint) focused on strengthening code generation and math word-problem solving, while retaining the general chat and instruction-following ability of the original instruct model.
21
+
22
+ ## Why this exists
23
+
24
+ LiquidAI's own model card for LFM2.5-230M states it is **not recommended for reasoning-heavy workloads such as advanced math, code generation, or creative writing** — the model is tuned primarily for data extraction, structured outputs, and lightweight agentic/tool-use tasks. This fine-tune is an attempt to push a small, efficient instruct model further into code and math competence without sacrificing its existing conversational ability.
25
+
26
+ Fine-tuning started from the **instruct** checkpoint rather than the base pretrain checkpoint, specifically to preserve chat and instruction-following behavior that the base model doesn't have. An earlier fine-tune attempt starting from `LFM2.5-230M-Base` produced a model that was strong at code/math but broke down on basic conversation (e.g. echoing "Hello, who are you?" back verbatim). Starting from instruct avoided this.
27
+
28
+ ## Training details
29
+
30
+ - **Base model**: `LiquidAI/LFM2.5-230M` (instruct)
31
+ - **Method**: Full fine-tune (LoRA would also work at this scale; full-FT was used here since compute wasn't a constraint)
32
+ - **Datasets**:
33
+ - Code: [`iamtarun/code_instructions_120k_alpaca`](https://huggingface.co/datasets/iamtarun/code_instructions_120k_alpaca)
34
+ - Math: [`openai/gsm8k`](https://huggingface.co/datasets/openai/gsm8k) (main split)
35
+ - **Checkpoint selection**: best checkpoint by eval loss (not final step) — training showed clear overfitting past ~step 7500, where training loss kept falling but eval loss plateaued/rose slightly. The published checkpoint is from before that point.
36
+ - **Sequence length**: 1024 tokens (dataset is short-form; base model supports up to 32K context)
37
+ - **Loss**: completion-only (loss computed only on assistant responses, not prompts)
38
+
39
+ ## What it's good at
40
+
41
+ Based on manual testing across ~20+ prompts spanning algebra, geometry, general code tasks, and open-ended chat:
42
+
43
+ - **Code**: Reliable on common patterns — string/list manipulation, simple classes, recursion, file I/O, prime checking, etc. In the author's own informal side-by-side testing, output was clearer and more consistent than Qwen2.5-Coder-0.5B-Instruct on the same prompts. This is a subjective, single-user comparison, not a formal benchmark — your results may differ.
44
+ - **Math**: Grade-school word problems (gsm8k-style), percentages, basic algebra, geometry (area/perimeter) — mostly correct with gsm8k-style step annotations.
45
+ - **Chat**: Retains coherent, on-topic conversational ability inherited from the instruct base — no repetition loops or echo failures observed in testing.
46
+ - **Tool calling**: Spot-checked informally by the author using the Pythonic tool-call format LFM2.5 supports; not systematically benchmarked against other models.
47
+
48
+ ## Known limitations
49
+
50
+ - Occasional arithmetic slip on multi-step algebra (e.g., correct method shown, final division not simplified).
51
+ - Not tested on data extraction or RAG.
52
+ - Still a 230M-parameter model — do not expect deep multi-step reasoning, advanced math, or long-form creative writing at the level of much larger models.
53
+ - Not evaluated on safety-critical, medical, or legal use cases — do not use for those without additional safeguards.
54
+
55
+ ## Usage
56
+
57
+ ```python
58
+ from transformers import AutoModelForCausalLM, AutoTokenizer
59
+
60
+ model_id = "hauser458original/lfm2.5-230m-code-math"
61
+ model = AutoModelForCausalLM.from_pretrained(model_id, dtype="bfloat16", device_map="auto")
62
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
63
+
64
+ messages = [{"role": "user", "content": "Write a Python function to check if a number is prime."}]
65
+ inputs = tokenizer.apply_chat_template(
66
+ messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
67
+ ).to(model.device)
68
+
69
+ output = model.generate(**inputs, max_new_tokens=300, do_sample=True, temperature=0.3, top_p=0.9)
70
+ print(tokenizer.decode(output[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
71
+ ```
72
+
73
+ GGUF quantized versions (Q4_K_M, Q5_K_S, Q5_K_M, Q8_0, F16) for llama.cpp/Ollama/LM Studio are available at: `hauser458original/lfm2.5-230m-code-math-GGUF`
74
+
75
+ ## License
76
+
77
+ Inherits the [LFM Open License v1.0](https://huggingface.co/LiquidAI/LFM2.5-230M/blob/main/LICENSE) from the base model.
78
+
79
+ ## Acknowledgements
80
+
81
+ Built on [LiquidAI/LFM2.5-230M](https://huggingface.co/LiquidAI/LFM2.5-230M). See the [LFM2 Technical Report](https://arxiv.org/abs/2511.23404) for details on the base architecture.
chat_template.jinja ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- bos_token -}}
2
+ {%- set preserve_thinking = preserve_thinking | default(false) -%}
3
+
4
+ {%- macro format_arg_value(arg_value) -%}
5
+ {%- if arg_value is string -%}
6
+ {{- "'" + arg_value + "'" -}}
7
+ {%- elif arg_value is mapping -%}
8
+ {{- arg_value | tojson -}}
9
+ {%- else -%}
10
+ {{- arg_value | string -}}
11
+ {%- endif -%}
12
+ {%- endmacro -%}
13
+
14
+ {%- macro parse_content(content) -%}
15
+ {%- if content is string -%}
16
+ {{- content -}}
17
+ {%- else -%}
18
+ {%- set _ns = namespace(result="") -%}
19
+ {%- for item in content -%}
20
+ {%- if item["type"] == "image" -%}
21
+ {%- set _ns.result = _ns.result + "<image>" -%}
22
+ {%- elif item["type"] == "text" -%}
23
+ {%- set _ns.result = _ns.result + item["text"] -%}
24
+ {%- else -%}
25
+ {%- set _ns.result = _ns.result + item | tojson -%}
26
+ {%- endif -%}
27
+ {%- endfor -%}
28
+ {{- _ns.result -}}
29
+ {%- endif -%}
30
+ {%- endmacro -%}
31
+
32
+ {%- macro render_tool_calls(tool_calls) -%}
33
+ {%- set tool_calls_ns = namespace(tool_calls=[]) -%}
34
+ {%- for tool_call in tool_calls -%}
35
+ {%- set func_name = tool_call["function"]["name"] -%}
36
+ {%- set func_args = tool_call["function"]["arguments"] -%}
37
+ {%- set args_ns = namespace(arg_strings=[]) -%}
38
+ {%- for arg_name, arg_value in func_args.items() -%}
39
+ {%- set args_ns.arg_strings = args_ns.arg_strings + [arg_name + "=" + format_arg_value(arg_value)] -%}
40
+ {%- endfor -%}
41
+ {%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [func_name + "(" + (args_ns.arg_strings | join(", ")) + ")"] -%}
42
+ {%- endfor -%}
43
+ {{- "<|tool_call_start|>[" + (tool_calls_ns.tool_calls | join(", ")) + "]<|tool_call_end|>" -}}
44
+ {%- endmacro -%}
45
+
46
+ {%- set ns = namespace(system_prompt="", last_user_index=-1) -%}
47
+ {%- if messages[0]["role"] == "system" -%}
48
+ {%- if messages[0].get("content") -%}
49
+ {%- set ns.system_prompt = parse_content(messages[0]["content"]) -%}
50
+ {%- endif -%}
51
+ {%- set messages = messages[1:] -%}
52
+ {%- endif -%}
53
+ {%- if tools -%}
54
+ {%- set ns.system_prompt = ns.system_prompt + ("\n" if ns.system_prompt else "") + "List of tools: [" -%}
55
+ {%- for tool in tools -%}
56
+ {%- if tool is not string -%}
57
+ {%- set tool = tool | tojson -%}
58
+ {%- endif -%}
59
+ {%- set ns.system_prompt = ns.system_prompt + tool -%}
60
+ {%- if not loop.last -%}
61
+ {%- set ns.system_prompt = ns.system_prompt + ", " -%}
62
+ {%- endif -%}
63
+ {%- endfor -%}
64
+ {%- set ns.system_prompt = ns.system_prompt + "]" -%}
65
+ {%- endif -%}
66
+ {%- if ns.system_prompt -%}
67
+ {{- "<|im_start|>system\n" + ns.system_prompt + "<|im_end|>\n" -}}
68
+ {%- endif -%}
69
+ {%- for message in messages -%}
70
+ {%- if message["role"] == "user" -%}
71
+ {%- set ns.last_user_index = loop.index0 -%}
72
+ {%- endif -%}
73
+ {%- endfor -%}
74
+ {%- for message in messages -%}
75
+ {{- "<|im_start|>" + message.role + "\n" -}}
76
+ {%- if message.role == "assistant" -%}
77
+ {%- generation -%}
78
+ {%- if message.thinking is defined and (preserve_thinking or loop.index0 > ns.last_user_index) -%}
79
+ {{- "<think>" + message.thinking + "</think>" -}}
80
+ {%- endif -%}
81
+ {%- set _cfm_tag = "CONTINUE_FINAL_MESSAGE_TAG " -%}
82
+ {%- set _has_cfm = false -%}
83
+ {%- if message.content is defined -%}
84
+ {%- set content = parse_content(message.content) -%}
85
+ {%- if not (preserve_thinking or loop.index0 > ns.last_user_index) -%}
86
+ {%- if "</think>" in content -%}
87
+ {%- set content = content.split("</think>")[-1] | trim -%}
88
+ {%- endif -%}
89
+ {%- endif -%}
90
+ {%- if message.tool_calls is defined and content.endswith(_cfm_tag) -%}
91
+ {%- set _has_cfm = true -%}
92
+ {%- set _trunc_len = (content | length) - (_cfm_tag | length) -%}
93
+ {{- content[:_trunc_len] -}}
94
+ {%- else -%}
95
+ {{- content -}}
96
+ {%- endif -%}
97
+ {%- endif -%}
98
+ {%- if message.tool_calls is defined -%}
99
+ {{- render_tool_calls(message.tool_calls) -}}
100
+ {%- endif -%}
101
+ {%- if _has_cfm -%}
102
+ {{- _cfm_tag -}}
103
+ {%- endif -%}
104
+ {{- "<|im_end|>\n" -}}
105
+ {%- endgeneration -%}
106
+ {%- else %}
107
+ {%- if message.get("content") -%}
108
+ {{- parse_content(message["content"]) -}}
109
+ {%- endif -%}
110
+ {{- "<|im_end|>\n" -}}
111
+ {%- endif %}
112
+ {%- endfor -%}
113
+ {%- if add_generation_prompt -%}
114
+ {{- "<|im_start|>assistant\n" -}}
115
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Lfm2ForCausalLM"
4
+ ],
5
+ "block__name_mlp": "parallel_mlp_merged",
6
+ "block_auto_adjust_ff_dim": false,
7
+ "block_dim": 1024,
8
+ "block_ffn_dim_multiplier": 1.0,
9
+ "block_ffn_te_autocast": false,
10
+ "block_ffn_use_quantized_params": false,
11
+ "block_mlp_init_scale": 1.0,
12
+ "block_multiple_of": 256,
13
+ "block_norm_eps": 1e-05,
14
+ "block_out_init_scale": 1.0,
15
+ "block_sequence_parallel_norm_across_tp": false,
16
+ "block_use_swiglu": true,
17
+ "block_use_xavier_init": true,
18
+ "bos_token_id": 1,
19
+ "conv_L_cache": 3,
20
+ "conv_bias": false,
21
+ "conv_dim": 1024,
22
+ "conv_use_xavier_init": true,
23
+ "dtype": "bfloat16",
24
+ "eos_token_id": 7,
25
+ "ffn_te_autocast": false,
26
+ "ffn_use_quantized_params": false,
27
+ "full_attn_idxs": null,
28
+ "hidden_size": 1024,
29
+ "initializer_range": 0.02,
30
+ "intermediate_size": 2560,
31
+ "layer_types": [
32
+ "conv",
33
+ "conv",
34
+ "full_attention",
35
+ "conv",
36
+ "full_attention",
37
+ "conv",
38
+ "full_attention",
39
+ "conv",
40
+ "full_attention",
41
+ "conv",
42
+ "full_attention",
43
+ "conv",
44
+ "full_attention",
45
+ "conv"
46
+ ],
47
+ "max_position_embeddings": 128000,
48
+ "model_type": "lfm2",
49
+ "norm_eps": 1e-05,
50
+ "num_attention_heads": 16,
51
+ "num_heads": 16,
52
+ "num_hidden_layers": 14,
53
+ "num_key_value_heads": 8,
54
+ "pad_token_id": 0,
55
+ "rope_parameters": {
56
+ "rope_theta": 1000000.0,
57
+ "rope_type": "default"
58
+ },
59
+ "sequence_parallel_norm_across_tp": false,
60
+ "tie_word_embeddings": true,
61
+ "transformers_version": "5.13.1",
62
+ "use_cache": false,
63
+ "use_pos_enc": true,
64
+ "vocab_size": 65536
65
+ }
generation_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 7
7
+ ],
8
+ "output_attentions": false,
9
+ "output_hidden_states": false,
10
+ "pad_token_id": 0,
11
+ "repetition_penalty": 1.05,
12
+ "temperature": 0.1,
13
+ "top_k": 50,
14
+ "transformers_version": "5.13.1",
15
+ "use_cache": true
16
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c36769afb89b9d66bbade7180a8c432f42f1ebeab801c2b3ca320cda2daedc55
3
+ size 459401112
optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28b38d69c685e5bba753a474ba101e8fe58481da9605bb2422717e19f3a74149
3
+ size 918884427
rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b553f29952467be16caa6cfed85b46b8eca2fcb747c960c969cf8f70b9c34ca9
3
+ size 14645
scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e0a88ed4e3c10590382e20c829879548cc984cb94fccc592e667aff7d90adf1d
3
+ size 1465
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<|startoftext|>",
4
+ "clean_up_tokenization_spaces": false,
5
+ "eos_token": "<|im_end|>",
6
+ "is_local": false,
7
+ "legacy": false,
8
+ "local_files_only": false,
9
+ "model_input_names": [
10
+ "input_ids",
11
+ "attention_mask"
12
+ ],
13
+ "model_max_length": 1000000000000000019884624838656,
14
+ "pad_token": "<|pad|>",
15
+ "sp_model_kwargs": {},
16
+ "spaces_between_special_tokens": false,
17
+ "tokenizer_class": "TokenizersBackend",
18
+ "use_default_system_prompt": false,
19
+ "use_fast": true
20
+ }
trainer_state.json ADDED
The diff for this file is too large to render. See raw diff
 
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:47efbf7138e22b3deed7c85939bba25147a8382cff16e57a1f50728f2ab2d2ea
3
+ size 5713