Text Generation
Transformers
Safetensors
lfm2
liquid
lfm2.5
weight-editing
model-editing
json
training-free
conversational
Instructions to use yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix") 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("yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix") model = AutoModelForCausalLM.from_pretrained("yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix", 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 yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix
- SGLang
How to use yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix 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 "yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix" \ --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": "yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix", "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 "yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix" \ --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": "yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix with Docker Model Runner:
docker model run hf.co/yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix
Download wsp/apply_patch.py from yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix/resolve/main/wsp/apply_patch.py
- Command line
-
hf download hf://yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix/wsp/apply_patch.py
-
curl -L -o apply_patch.py https://huggingface.co/yasserrmd/LFM2.5-1.2B-Instruct-WSP-JSONFix/resolve/main/wsp/apply_patch.py
2.1 kB
| """Deterministic apply/revert of a WSP sparse patch to a native safetensors checkpoint (no training, no grad). | |
| Usage: | |
| python src/apply_patch.py --base <snapshot_dir> --patch patches/chosen_patch.safetensors --manifest patches/chosen_patch.json --out <out_dir> | |
| python src/apply_patch.py --base <edited_dir> --patch ... --manifest ... --out <restored_dir> --revert | |
| Never writes into --base.""" | |
| import argparse, os, shutil, json, hashlib, torch | |
| from safetensors.torch import load_file, save_file | |
| import sys; sys.path.insert(0, os.path.dirname(__file__)) | |
| import wsp_patch as WP | |
| def apply_to_state(sd, patch, reverse=False): | |
| n = 0 | |
| for name, t in patch["tensors"].items(): | |
| flat = sd[name].view(-1) | |
| expect = t["new"] if reverse else t["orig"] | |
| if not torch.equal(flat[t["idx"]].view(torch.int16), expect.view(torch.int16)): | |
| raise ValueError(f"precondition failed for {name}: coordinates are not in the expected {'edited' if reverse else 'original'} state") | |
| flat[t["idx"]] = t["orig"] if reverse else t["new"]; n += t["idx"].numel() | |
| return n | |
| def main(): | |
| ap = argparse.ArgumentParser(); ap.add_argument("--base", required=True); ap.add_argument("--patch", required=True) | |
| ap.add_argument("--manifest", required=True); ap.add_argument("--out", required=True); ap.add_argument("--revert", action="store_true") | |
| a = ap.parse_args() | |
| assert os.path.realpath(a.out) != os.path.realpath(a.base), "refusing to overwrite base" | |
| patch = WP.load(a.patch, a.manifest) | |
| os.makedirs(a.out, exist_ok=True) | |
| for fn in os.listdir(a.base): | |
| p = os.path.join(a.base, fn) | |
| if os.path.isfile(p) and not fn.endswith(".safetensors"): shutil.copy(p, os.path.join(a.out, fn)) | |
| sd = load_file(os.path.join(a.base, "model.safetensors")) | |
| n = apply_to_state(sd, patch, reverse=a.revert) | |
| save_file({k: v.contiguous() for k, v in sd.items()}, os.path.join(a.out, "model.safetensors"), metadata={"format": "pt"}) | |
| print(json.dumps({"written": a.out, "coordinates": n, "revert": a.revert})) | |
| if __name__ == "__main__": main() | |