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
| 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() | |