Instructions to use namanadep/Mamba-7B-Reasoning with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use namanadep/Mamba-7B-Reasoning with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
File size: 2,741 Bytes
47f143c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | import json
import os
from datasets import load_dataset
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import config
def format_conversations(conversations):
text_parts = []
system_prompt = "You are an advanced AI reasoning assistant powered by a Selective State Space Model. You solve complex problems step-by-step using internal reasoning traces wrapped in <think>...</think> tags."
text_parts.append(f"<|im_start|>system\n{system_prompt}<|im_end|>\n")
for msg in conversations:
role = msg.get("from", "user")
if role in ["human", "user"]:
role_name = "user"
else:
role_name = "assistant"
content = msg.get("value", "")
text_parts.append(f"<|im_start|>{role_name}\n{content}<|im_end|>\n")
return "".join(text_parts)
def main():
print(f"Loading reasoning dataset: {config.DATASET_ID}...")
ds = load_dataset(config.DATASET_ID, split="train")
os.makedirs(config.DATA_DIR, exist_ok=True)
os.makedirs(config.RESULTS_DIR, exist_ok=True)
os.makedirs(config.DOCS_DIR, exist_ok=True)
total = len(ds)
print(f"Loaded {total} samples. Processing and split into train, val, eval_100...")
processed = []
eval_prompts = []
for idx, sample in enumerate(ds):
convs = sample.get("conversations", [])
if not convs:
continue
full_text = format_conversations(convs)
processed.append({"text": full_text})
if len(eval_prompts) < 100:
user_msg = ""
for msg in convs:
if msg.get("from") in ["human", "user"]:
user_msg = msg.get("value", "")
break
if user_msg:
eval_prompts.append({
"id": len(eval_prompts) + 1,
"prompt": user_msg
})
train_data = processed[:13500]
val_data = processed[13500:15000]
print(f"Writing {len(train_data)} train samples to {config.TRAIN_FILE}...")
with open(config.TRAIN_FILE, "w", encoding="utf-8") as f:
for item in train_data:
f.write(json.dumps(item) + "\n")
print(f"Writing {len(val_data)} validation samples to {config.VAL_FILE}...")
with open(config.VAL_FILE, "w", encoding="utf-8") as f:
for item in val_data:
f.write(json.dumps(item) + "\n")
print(f"Writing 100 holdout eval prompts to {config.EVAL_FILE}...")
with open(config.EVAL_FILE, "w", encoding="utf-8") as f:
json.dump(eval_prompts, f, indent=2)
print("Dataset preparation complete!")
if __name__ == "__main__":
main()
|