初始化项目,由ModelHub XC社区提供模型
Model: jtregunna/cobrachicken-swe-1.2b Source: Original Platform
This commit is contained in:
35
.gitattributes
vendored
Normal file
35
.gitattributes
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
182
README.md
Normal file
182
README.md
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
---
|
||||||
|
license: other
|
||||||
|
license_name: lfm-1.0
|
||||||
|
license_link: https://huggingface.co/LiquidAI/LFM2.5-1.2B-Instruct/blob/main/LICENSE
|
||||||
|
base_model: LiquidAI/LFM2.5-1.2B-Instruct
|
||||||
|
tags:
|
||||||
|
- lfm2
|
||||||
|
- sft
|
||||||
|
- software-engineering
|
||||||
|
- structured-output
|
||||||
|
- strategist
|
||||||
|
- routing
|
||||||
|
language:
|
||||||
|
- en
|
||||||
|
pipeline_tag: text-generation
|
||||||
|
library_name: transformers
|
||||||
|
datasets:
|
||||||
|
- jtregunna/software-strategist-v1
|
||||||
|
---
|
||||||
|
|
||||||
|
# cobrachicken-swe
|
||||||
|
|
||||||
|
A fine-tuned version of [LFM2.5-1.2B-Instruct](https://huggingface.co/LiquidAI/LFM2.5-1.2B-Instruct) that acts as a strategic concept router for software engineering tasks. Given a developer's coding request, it identifies which strategic concept(s) from a 518-entry knowledge base apply and synthesizes structured guidance for a downstream coding model to consume.
|
||||||
|
|
||||||
|
Designed as a **fast pre-processor**: it runs before a larger coding model and outputs JSON guidance that gets injected into the downstream model's prompt alongside the user's original request.
|
||||||
|
|
||||||
|
## Quick start
|
||||||
|
|
||||||
|
```python
|
||||||
|
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||||
|
import torch
|
||||||
|
|
||||||
|
tok = AutoTokenizer.from_pretrained("jtregunna/cobrachicken-swe")
|
||||||
|
model = AutoModelForCausalLM.from_pretrained(
|
||||||
|
"jtregunna/cobrachicken-swe",
|
||||||
|
dtype=torch.bfloat16,
|
||||||
|
device_map="cuda:0",
|
||||||
|
)
|
||||||
|
|
||||||
|
SYSTEM = (
|
||||||
|
"You are a software engineering strategist. Analyze user requests and "
|
||||||
|
"output strategic guidance as JSON with concepts_applied (0-3 concepts "
|
||||||
|
"with id, name, weight), core_idea (synthesized framing), key_principles "
|
||||||
|
"(3-5 actionable items), and avoid (1-3 warnings)."
|
||||||
|
)
|
||||||
|
|
||||||
|
messages = [
|
||||||
|
{"role": "system", "content": SYSTEM},
|
||||||
|
{"role": "user", "content": "I just inherited a 600-line Flask app from someone who left and I have no idea where to start understanding it."},
|
||||||
|
]
|
||||||
|
|
||||||
|
ids = tok.apply_chat_template(
|
||||||
|
messages,
|
||||||
|
add_generation_prompt=True,
|
||||||
|
return_tensors="pt",
|
||||||
|
tokenize=True,
|
||||||
|
)
|
||||||
|
if hasattr(ids, "input_ids"):
|
||||||
|
ids = ids.input_ids
|
||||||
|
ids = ids.to(model.device)
|
||||||
|
|
||||||
|
out = model.generate(
|
||||||
|
input_ids=ids,
|
||||||
|
attention_mask=torch.ones_like(ids),
|
||||||
|
max_new_tokens=512,
|
||||||
|
do_sample=False,
|
||||||
|
pad_token_id=tok.eos_token_id,
|
||||||
|
)
|
||||||
|
print(tok.decode(out[0][ids.shape[1]:], skip_special_tokens=True))
|
||||||
|
```
|
||||||
|
|
||||||
|
Example output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"concepts_applied": [
|
||||||
|
{"id": "sf-legacy-code-001", "name": "Legacy Code Strategies", "weight": "primary"}
|
||||||
|
],
|
||||||
|
"core_idea": "Start by creating a 'map' of the system's components rather than trying to understand every line of code immediately. Identify the entry points and trace a few key user journeys to build a mental model of the application's flow.",
|
||||||
|
"key_principles": [
|
||||||
|
"Identify the main entry point and trace a few key user journeys to understand the application flow.",
|
||||||
|
"Create a component map to identify the different modules and their responsibilities.",
|
||||||
|
"Write simple integration tests for the identified entry points to verify basic functionality before diving deeper."
|
||||||
|
],
|
||||||
|
"avoid": [
|
||||||
|
"Trying to understand every function and variable immediately.",
|
||||||
|
"Refactoring the entire codebase before understanding it."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Output schema
|
||||||
|
|
||||||
|
Every response is a JSON object with these fields:
|
||||||
|
|
||||||
|
| Field | Type | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `concepts_applied` | array (0-3) | Concepts that apply to the input. Each has `id`, `name`, and `weight` (`primary` or `secondary`). Exactly one is marked `primary` when non-empty. Empty array when no concept applies. |
|
||||||
|
| `core_idea` | string \| null | 1-3 sentence synthesized framing, tailored to the specific input. `null` when no concept applies. |
|
||||||
|
| `key_principles` | array of strings | 3-5 actionable items derived from the applicable concepts, phrased for the user's situation. Empty when no concept applies. |
|
||||||
|
| `avoid` | array of strings | 1-3 warnings derived from anti-patterns associated with the concepts. Empty when no concept applies. |
|
||||||
|
|
||||||
|
## System prompt
|
||||||
|
|
||||||
|
The model was trained with variations on system prompts related to the role of being a software strategist. Small models are sensitive to prompt drift, and centering your prompt on other roles, could degrade schema conformance and routing accuracy:
|
||||||
|
|
||||||
|
Example prompt for variation generation:
|
||||||
|
|
||||||
|
```
|
||||||
|
You are a software engineering strategist. Analyze user requests and output strategic guidance as JSON with concepts_applied (0-3 concepts with id, name, weight), core_idea (synthesized framing), key_principles (3-5 actionable items), and avoid (1-3 warnings).
|
||||||
|
```
|
||||||
|
|
||||||
|
## Intended use
|
||||||
|
|
||||||
|
- **Fast pre-processor** before a larger coding-focused model (Claude, GPT, Qwen Coder, etc.)
|
||||||
|
- Strategic steering for code review, debugging assistance, architecture discussions, and onboarding scenarios
|
||||||
|
- Latency-sensitive inference: ~25 ms TTFT, ~231 tok/s decode on a single RTX A6000 in vLLM
|
||||||
|
|
||||||
|
Not designed for: direct end-user-facing chat, code generation, knowledge-intensive Q&A, or stand-alone deployment without a downstream model.
|
||||||
|
|
||||||
|
## Performance
|
||||||
|
|
||||||
|
Measured on a single RTX A6000 (48 GB), bf16, HuggingFace `transformers` eager mode, batch size 1:
|
||||||
|
|
||||||
|
| Metric | Value |
|
||||||
|
|---|---|
|
||||||
|
| Time to first token (median) | ~24 ms |
|
||||||
|
| Prefill throughput | 3,000-10,000 tok/s (scales with prompt length) |
|
||||||
|
| Decode throughput | ~231 tok/s |
|
||||||
|
| End-to-end latency (typical ~200 tok output) | ~1.5 s |
|
||||||
|
|
||||||
|
|
||||||
|
## Training
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
| **Base model** | [LiquidAI/LFM2.5-1.2B-Instruct](https://huggingface.co/LiquidAI/LFM2.5-1.2B-Instruct) |
|
||||||
|
| **Method** | Full SFT (no LoRA) |
|
||||||
|
| **Framework** | [leap-finetune](https://github.com/Liquid4All/leap-finetune) (Liquid AI) |
|
||||||
|
| **Hardware** | 2× RTX A6000 |
|
||||||
|
| **Dataset** | ~13,500 synthetic examples from a teacher model |
|
||||||
|
| **Epochs** | 3 |
|
||||||
|
| **Learning rate** | 3e-6 (cosine schedule, 5% warmup) |
|
||||||
|
| **Batch size** | 2 per device × 2 GPUs × 4 grad accum = 16 effective |
|
||||||
|
| **Sequence length** | 4096 |
|
||||||
|
| **Precision** | bfloat16 |
|
||||||
|
| **Training time** | ~90 minutes |
|
||||||
|
|
||||||
|
## Known limitations
|
||||||
|
|
||||||
|
- **Null discipline.** The model tends to route most inputs to *some* concept rather than returning `concepts_applied: []` for off-topic or trivial inputs (e.g. "rename `x` to `y`", "what's the weather"). Downstream consumers should be tolerant of occasionally irrelevant guidance, or filter outputs by a confidence/relevance signal.
|
||||||
|
|
||||||
|
- **System prompt sensitivity.** System prompt needs to be on topic as a software strategist.
|
||||||
|
|
||||||
|
- **Synthesis quality bounded by teacher data.** Outputs are well-structured but occasionally read as templated. Quality is upper-bounded by the teacher model used to generate the training data.
|
||||||
|
|
||||||
|
- **Concept coverage.** Performance is best on concepts with high training-example density. Long-tail concepts may be less reliably routed.
|
||||||
|
|
||||||
|
- **English-only.** Training data was English; behavior in other languages is untested and likely degraded.
|
||||||
|
|
||||||
|
- **Not for general chat.** This is a specialized routing model. It will attempt to produce structured JSON for any input, including ones where free-form prose would be more appropriate.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This model is released under the [**LFM Open License**](https://huggingface.co/LiquidAI/LFM2.5-1.2B-Instruct/blob/main/LICENSE), inherited from the base model LFM2.5-1.2B-Instruct.
|
||||||
|
|
||||||
|
## Citation
|
||||||
|
|
||||||
|
If you use this model, please also cite the base model:
|
||||||
|
|
||||||
|
```bibtex
|
||||||
|
@misc{liquidai2024lfm2,
|
||||||
|
title={LFM2.5: A Family of Hybrid Models},
|
||||||
|
author={Liquid AI},
|
||||||
|
year={2024},
|
||||||
|
url={https://huggingface.co/LiquidAI/LFM2.5-1.2B-Instruct}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Acknowledgments
|
||||||
|
|
||||||
|
- [Liquid AI](https://liquid.ai) for the LFM2.5 base model and the leap-finetune training framework
|
||||||
45
chat_template.jinja
Normal file
45
chat_template.jinja
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{{- bos_token -}}
|
||||||
|
{%- set keep_past_thinking = keep_past_thinking | default(false) -%}
|
||||||
|
{%- set ns = namespace(system_prompt="") -%}
|
||||||
|
{%- if messages[0]["role"] == "system" -%}
|
||||||
|
{%- set ns.system_prompt = messages[0]["content"] -%}
|
||||||
|
{%- set messages = messages[1:] -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- if tools -%}
|
||||||
|
{%- set ns.system_prompt = ns.system_prompt + ("\n" if ns.system_prompt else "") + "List of tools: [" -%}
|
||||||
|
{%- for tool in tools -%}
|
||||||
|
{%- if tool is not string -%}
|
||||||
|
{%- set tool = tool | tojson -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- set ns.system_prompt = ns.system_prompt + tool -%}
|
||||||
|
{%- if not loop.last -%}
|
||||||
|
{%- set ns.system_prompt = ns.system_prompt + ", " -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- set ns.system_prompt = ns.system_prompt + "]" -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- if ns.system_prompt -%}
|
||||||
|
{{- "<|im_start|>system\n" + ns.system_prompt + "<|im_end|>\n" -}}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- set ns.last_assistant_index = -1 -%}
|
||||||
|
{%- for message in messages -%}
|
||||||
|
{%- if message["role"] == "assistant" -%}
|
||||||
|
{%- set ns.last_assistant_index = loop.index0 -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- for message in messages -%}
|
||||||
|
{{- "<|im_start|>" + message["role"] + "\n" -}}
|
||||||
|
{%- set content = message["content"] -%}
|
||||||
|
{%- if content is not string -%}
|
||||||
|
{%- set content = content | tojson -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- if message["role"] == "assistant" and not keep_past_thinking and loop.index0 != ns.last_assistant_index -%}
|
||||||
|
{%- if "</think>" in content -%}
|
||||||
|
{%- set content = content.split("</think>")[-1] | trim -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{{- content + "<|im_end|>\n" -}}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- if add_generation_prompt -%}
|
||||||
|
{{- "<|im_start|>assistant\n" -}}
|
||||||
|
{%- endif -%}
|
||||||
61
config.json
Normal file
61
config.json
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"architectures": [
|
||||||
|
"Lfm2ForCausalLM"
|
||||||
|
],
|
||||||
|
"block_auto_adjust_ff_dim": true,
|
||||||
|
"block_dim": 2048,
|
||||||
|
"block_ff_dim": 12288,
|
||||||
|
"block_ffn_dim_multiplier": 1.0,
|
||||||
|
"block_mlp_init_scale": 1.0,
|
||||||
|
"block_multiple_of": 256,
|
||||||
|
"block_norm_eps": 1e-05,
|
||||||
|
"block_out_init_scale": 1.0,
|
||||||
|
"block_use_swiglu": true,
|
||||||
|
"block_use_xavier_init": true,
|
||||||
|
"bos_token_id": 1,
|
||||||
|
"conv_L_cache": 3,
|
||||||
|
"conv_bias": false,
|
||||||
|
"conv_dim": 2048,
|
||||||
|
"conv_use_xavier_init": true,
|
||||||
|
"dtype": "bfloat16",
|
||||||
|
"eos_token_id": 7,
|
||||||
|
"hidden_size": 2048,
|
||||||
|
"initializer_range": 0.02,
|
||||||
|
"intermediate_size": 12288,
|
||||||
|
"layer_types": [
|
||||||
|
"conv",
|
||||||
|
"conv",
|
||||||
|
"full_attention",
|
||||||
|
"conv",
|
||||||
|
"conv",
|
||||||
|
"full_attention",
|
||||||
|
"conv",
|
||||||
|
"conv",
|
||||||
|
"full_attention",
|
||||||
|
"conv",
|
||||||
|
"full_attention",
|
||||||
|
"conv",
|
||||||
|
"full_attention",
|
||||||
|
"conv",
|
||||||
|
"full_attention",
|
||||||
|
"conv"
|
||||||
|
],
|
||||||
|
"max_position_embeddings": 128000,
|
||||||
|
"model_type": "lfm2",
|
||||||
|
"norm_eps": 1e-05,
|
||||||
|
"num_attention_heads": 32,
|
||||||
|
"num_heads": 32,
|
||||||
|
"num_hidden_layers": 16,
|
||||||
|
"num_key_value_heads": 8,
|
||||||
|
"pad_token_id": 0,
|
||||||
|
"rope_parameters": {
|
||||||
|
"rope_theta": 1000000.0,
|
||||||
|
"rope_type": "default"
|
||||||
|
},
|
||||||
|
"tie_embedding": true,
|
||||||
|
"tie_word_embeddings": true,
|
||||||
|
"transformers_version": "5.2.0",
|
||||||
|
"use_cache": false,
|
||||||
|
"use_pos_enc": true,
|
||||||
|
"vocab_size": 65536
|
||||||
|
}
|
||||||
9
generation_config.json
Normal file
9
generation_config.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"_from_model_config": true,
|
||||||
|
"bos_token_id": 1,
|
||||||
|
"eos_token_id": [
|
||||||
|
7
|
||||||
|
],
|
||||||
|
"pad_token_id": 0,
|
||||||
|
"transformers_version": "5.2.0"
|
||||||
|
}
|
||||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:5e2c1f2997c33f9e54060aefde46b2d4f424fd7d095dda31f379547e98f4a1b0
|
||||||
|
size 2609133520
|
||||||
323830
tokenizer.json
Normal file
323830
tokenizer.json
Normal file
File diff suppressed because it is too large
Load Diff
19
tokenizer_config.json
Normal file
19
tokenizer_config.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"backend": "tokenizers",
|
||||||
|
"bos_token": "<|startoftext|>",
|
||||||
|
"clean_up_tokenization_spaces": false,
|
||||||
|
"eos_token": "<|im_end|>",
|
||||||
|
"is_local": false,
|
||||||
|
"legacy": false,
|
||||||
|
"model_input_names": [
|
||||||
|
"input_ids",
|
||||||
|
"attention_mask"
|
||||||
|
],
|
||||||
|
"model_max_length": 1000000000000000019884624838656,
|
||||||
|
"pad_token": "<|pad|>",
|
||||||
|
"sp_model_kwargs": {},
|
||||||
|
"spaces_between_special_tokens": false,
|
||||||
|
"tokenizer_class": "TokenizersBackend",
|
||||||
|
"use_default_system_prompt": false,
|
||||||
|
"use_fast": true
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user