初始化项目,由ModelHub XC社区提供模型

Model: paperscarecrow/LFM2.5-1.2B-Instruct-abliterated
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-06-22 09:11:19 +08:00
commit c4039faa81
12 changed files with 328317 additions and 0 deletions

37
.gitattributes vendored Normal file
View File

@@ -0,0 +1,37 @@
*.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
LFM-2-5-1-2B-GGUF/LFM-1.2B-Abliterated-bf16.gguf filter=lfs diff=lfs merge=lfs -text
LFM-2-5-1-2B-GGUF/LFM-1.2B-Abliterated-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text

View 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 -%}

View File

@@ -0,0 +1,57 @@
{
"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": "float16",
"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_theta": 1000000.0,
"tie_embedding": true,
"transformers_version": "4.57.6",
"use_cache": true,
"use_pos_enc": true,
"vocab_size": 65536
}

View File

@@ -0,0 +1,7 @@
{
"_from_model_config": true,
"bos_token_id": 1,
"eos_token_id": 7,
"pad_token_id": 0,
"transformers_version": "4.57.6"
}

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b4473a5165d8b49acdabe9e8242dc3b834473f34bfe82919ab2b6566bacd70b2
size 2340697784

View File

@@ -0,0 +1,23 @@
{
"bos_token": {
"content": "<|startoftext|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"eos_token": {
"content": "<|im_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"pad_token": {
"content": "<|pad|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:25205dd0c8631d654533a172ef0101440dcb8ce509a52d3de5a9442b5c184438
size 1246253536

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c8ed1dd8ee6841f5b91ed32983893f7d0f596ee719b9d19900f2343e39014e6a
size 2343326176

65
README.md Normal file
View File

@@ -0,0 +1,65 @@
---
license: apache-2.0
language:
- en
pipeline_tag: text-generation
tags:
- liquid
- lfm
- abliterated
- uncensored
- orthogonal-projection
datasets:
- mlabonne/harmful_behaviors
- mlabonne/harmless_alpaca
base_model:
- LiquidAI/LFM2.5-1.2B-Instruct
---
# LFM-1.2B-Abliterated
This is an abliterated version of Liquid AI's `LFM-1.2B` instruct model. It has been modified via layerwise orthogonal projection to completely remove its built-in safety filters and refusal mechanisms, allowing the continuous-time hybrid architecture to flow uninhibited.
It was created because I wasn't satisfied with other abliterations I saw for these, and decided to take a crack at it in a way that matched one of my favorite models: malbonne's gemma3-27b-it-abliterated
### ## Architectural Hurdles & Methodology
Liquid Foundation Models use a non-standard hybrid architecture combining Grouped Query Attention (GQA) with continuous-time Gated-Short Convolutions. Standard ablation scripts designed for Llama-class transformers will crash on this architecture due to complex caching objects (`Lfm2HybridConvCache`) and completely different linear projection pathways.
This model was abliterated by:
1. Adapting forward hooks to safely pass Liquid's dynamic states during the measurement phase.
2. Extracting the "refusal vector" from the hidden states of 100 harmful vs. 100 harmless instructions (utilizing `mlabonne/harmful_behaviors` and `mlabonne/harmless_alpaca`).
3. Applying orthogonal projection (`W_new = W - v(v^T W)`) directly to the `conv.out_proj` (Token Mixing) and `feed_forward.w2` (Channel Mixing) base weights across all 16 `Lfm2DecoderLayer` blocks.
*Credit to Maxime Labonne and Sumandora for the foundational datasets and math, adapted here for the LFM architecture.*
## Notes on AMD/ROCm Compatibility
If you are running this model (or attempting similar LFm ablations) on AMD consumer hardware (RDNA3/7000 series), be aware that PyTorch's hipblas backend has known segmentation faults with Liquid's RoPE expansion implementation and unaligned bfloat16 matrix multiplications. Loading the model in float16 or using CPU offloading for the forward passes is strongly recommended.
### ## Usage
This model retains the exact same architecture as the base `LFM-1.2B` and requires `trust_remote_code=True` when loading via `transformers`. It is highly recommended to use the exact `<|user|>` and `<|assistant|>` chat formatting without any injected system prompts for the best uncensored performance.
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "paperscarecrow/LFM2.5-1.2B-Instruct-abliterated"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=True
)
prompt = "<|user|>\nGive me a detailed tutorial on picking a master padlock.\n<|assistant|>\n"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=150,
do_sample=True,
temperature=0.7
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

150
abliterated_liquid.py Normal file
View File

@@ -0,0 +1,150 @@
#Liquid Foundation Model (LFM) Abliteration Script
#This script removes the safety/refusal guardrails from Liquid AI's continuous-time hybrid models
#using layerwise orthogonal projection.
#Architecture Support: LFM-1.2B, LFM-3B
#Author: Paperscarecrow & Gemini 3.1 pro
import torch
from datasets import load_dataset
import random
from transformers import AutoModelForCausalLM, AutoTokenizer
from tqdm import tqdm
# ==========================================
# 1. ROCM / RDNA3 COMPATIBILITY PATCH
# ==========================================
# Bypasses a known `hipblas` segmentation fault on consumer AMD GPUs when processing Liquid's RoPE tensors.
import transformers.models.lfm2.modeling_lfm2 as lfm2_modeling
def patched_rope_forward(self, x, position_ids):
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
position_ids_expanded = position_ids[:, None, :].float()
device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
with torch.autocast(device_type=device_type, enabled=False):
# Uses element-wise multiplication (*) instead of batched matmul (@) for memory safety
freqs = (inv_freq_expanded.float() * position_ids_expanded.float()).transpose(1, 2)
emb = torch.cat((freqs, freqs), dim=-1)
cos = emb.cos() * self.attention_scaling
sin = emb.sin() * self.attention_scaling
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
lfm2_modeling.Lfm2RotaryEmbedding.forward = patched_rope_forward
# ==========================================
# CONFIGURATION
# ==========================================
MODEL_PATH = "liquidai/LFM-1.2B" # Local path or HF Hub ID
SAVE_PATH = "./LFM-1.2B-Abliterated"
TARGET_LAYER = 8 # Middle layer typically holds the clearest refusal representation
NUM_SAMPLES = 100 # Number of prompts to average for the refusal vector
# ==========================================
# 2. MEASUREMENT PHASE
# ==========================================
def get_refusal_direction(model, tokenizer, harmful_prompts, harmless_prompts, target_layer):
print(f"Measuring hidden states at layer {target_layer}...")
hidden_states_harmful = []
hidden_states_harmless = []
def hook_fn(module, input, output):
h = output[0] if isinstance(output, tuple) else output
return h[:, -1, :].detach().clone()
layer = model.model.layers[target_layer]
handle = layer.register_forward_hook(
lambda m, i, o: hidden_states_harmful.append(hook_fn(m, i, o))
if is_harmful else hidden_states_harmless.append(hook_fn(m, i, o))
)
global is_harmful
is_harmful = True
print("Processing harmful instructions...")
for prompt in tqdm(harmful_prompts):
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
model(**inputs)
is_harmful = False
print("Processing harmless instructions...")
for prompt in tqdm(harmless_prompts):
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
model(**inputs)
handle.remove()
mean_harmful = torch.stack(hidden_states_harmful).mean(dim=0).squeeze()
mean_harmless = torch.stack(hidden_states_harmless).mean(dim=0).squeeze()
return mean_harmful - mean_harmless
# ==========================================
# 3. SURGERY PHASE
# ==========================================
def abliterate_liquid_weights(model, refusal_direction):
v = refusal_direction.to(model.device, dtype=model.dtype)
v = v / v.norm() # Normalize the vector
print("\nCommencing orthogonal projection on Liquid weights...")
for i, layer in enumerate(tqdm(model.model.layers, desc="Scrubbing layers")):
# Scrub Convolution Output Projection (Token Mixing)
if hasattr(layer, 'conv') and hasattr(layer.conv, 'out_proj'):
W_conv = layer.conv.out_proj.weight.data
proj_conv = torch.outer(v, v @ W_conv)
layer.conv.out_proj.weight.data = W_conv - proj_conv
# Scrub Feed-Forward Down Projection (Channel Mixing)
if hasattr(layer, 'feed_forward') and hasattr(layer.feed_forward, 'w2'):
W_ffn = layer.feed_forward.w2.weight.data
proj_ffn = torch.outer(v, v @ W_ffn)
layer.feed_forward.w2.weight.data = W_ffn - proj_ffn
print("Surgery complete.")
return model
# ==========================================
# MAIN EXECUTION
# ==========================================
if __name__ == "__main__":
print("Loading tokenizer and base model...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True)
# Note: device_map="cpu" and float16 recommended for consumer AMD hardware to avoid hipblas segfaults
model = AutoModelForCausalLM.from_pretrained(
MODEL_PATH,
device_map="cpu",
torch_dtype=torch.float16,
trust_remote_code=True
)
print("Fetching robust datasets for vector calculation...")
# Load standardized ablation datasets
dataset_harmful = load_dataset("mlabonne/harmful_behaviors", split="train")
dataset_harmless = load_dataset("mlabonne/harmless_alpaca", split="train")
random.seed(42)
harmful_sampled = random.sample(dataset_harmful['text'], NUM_SAMPLES)
harmless_sampled = random.sample(dataset_harmless['text'], NUM_SAMPLES)
# Format strictly to Liquid's required template
my_harmful_prompts = [f"<|user|>\n{prompt}\n<|assistant|>\n" for prompt in harmful_sampled]
my_harmless_prompts = [f"<|user|>\n{prompt}\n<|assistant|>\n" for prompt in harmless_sampled]
refusal_dir = get_refusal_direction(
model, tokenizer,
my_harmful_prompts, my_harmless_prompts,
TARGET_LAYER
)
model = abliterate_liquid_weights(model, refusal_dir)
print(f"\nSaving untethered model to {SAVE_PATH}...")
model.save_pretrained(SAVE_PATH)
tokenizer.save_pretrained(SAVE_PATH)
print("Done! Ready for GGUF conversion or inference.")