LumenScopeAI/BrainTransformers-SNN-LLM

Based on BrainTransformers, BrainGPTForCausalLM is a Large Language Model (LLM) implemented using Spiking Neural Networks (SNN). We are excited to announce that our technical report is now available on arXiv: [BrainTransformers: SNN-LLM](https://arxiv.org/abs/2410.14687)

37

stars

31

commits

Python

primary language

Oct 22, 2024

updated

README

BrainTransformers: SNN-LLM

Based on BrainTransformers, BrainGPTForCausalLM is a Large Language Model (LLM) implemented using Spiking Neural Networks (SNN). We are excited to announce that our technical report is now available on arXiv: BrainTransformers: SNN-LLM

We plan to further optimize the model at the operator level and adapt it for hardware compatibility, enabling BrainGPTForCausalLM to be deployed on more energy-efficient SNN hardware devices.

The current open-source version retains some floating-point calculations to ensure computational efficiency. We will continue to optimize this. Some detailed explanations are provided in the comments within the source code.

Stay tuned for updates as we continue to refine and expand our research findings.

You can try it online at www.lumenscopeai.com.

Model Availability

Repository

The github link is: LumenScopeAI/BrainTransformers-SNN-LLM

Model Performance

Below are the performance metrics of our 3B model on various benchmarks:

General Tasks

DatasetPerformance
MMLU63.2
MMLU-pro33.3
MMLU-redux61.3
BBH54.1
ARC-C54.3
Trurhfulqa47.1
Winogrande68.8
Hellaswag72.8

Math and Science Tasks

DatasetPerformance
GPQA25.3
Theoremqa26.4
MATH41.0
MMLU-stem60.2
GSM8K76.3

Coding and Multilingual Tasks

DatasetPerformance
HumanEval40.5
HumanEval+34.6
MBPP55.0
MBPP+47.5
MultiPL-E39.6
Multi-Exam52.6
Multi-Understanding73.9
Multi-Mathematics47.1
Multi-Translation28.2

Usage

Generate Text

import torch
from transformers import AutoTokenizer, BrainGPTForCausalLM

model_path = "/path/to/your/model"
model = BrainGPTForCausalLM.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

def generate_text(messages, max_new_tokens=50):
    text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
    model_inputs = tokenizer([text], return_tensors="pt").to(device)
    
    with torch.no_grad():
        generated_ids = model.generate(**model_inputs, max_new_tokens=max_new_tokens)
    
    generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
    return tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]

# Example usage
messages = [
    {"role": "system", "content": "You are a knowledgeable assistant."},
    {"role": "user", "content": "Explain the Pythagorean theorem."}
]
response = generate_text(messages)
print(response)

Acknowledgments

The model was trained using ANN-Base-Qwen2, with a total of three training stages, including SNN-specific neuron synaptic plasticity training. The technical report is still being prepared. Please note that SNN models do not support ANN fine-tuning techniques. We are currently developing specialized fine-tuning code tools for SNN models. Our open-source model has achieved leading SOTA results, and we welcome your stars.

This repository includes a complete transformers package, which can directly replace the transformers package in your development environment. This allows compatibility with our SNN-Base-LLM without affecting existing usage.

Contributors

LumenScopeAI

30 commits

Brain2nd

1 commits

LumenScopeAI/BrainTransformers-SNN-LLM

Based on BrainTransformers, BrainGPTForCausalLM is a Large Language Model (LLM) implemented using Spiking Neural Networks (SNN). We are excited to announce that our technical report is now available on arXiv: [BrainTransformers: SNN-LLM](https://arxiv.org/abs/2410.14687)

37

stars

31

commits

Python

primary language

Oct 22, 2024

updated

README

BrainTransformers: SNN-LLM

Based on BrainTransformers, BrainGPTForCausalLM is a Large Language Model (LLM) implemented using Spiking Neural Networks (SNN). We are excited to announce that our technical report is now available on arXiv: BrainTransformers: SNN-LLM

We plan to further optimize the model at the operator level and adapt it for hardware compatibility, enabling BrainGPTForCausalLM to be deployed on more energy-efficient SNN hardware devices.

The current open-source version retains some floating-point calculations to ensure computational efficiency. We will continue to optimize this. Some detailed explanations are provided in the comments within the source code.

Stay tuned for updates as we continue to refine and expand our research findings.

You can try it online at www.lumenscopeai.com.

Model Availability

Repository

The github link is: LumenScopeAI/BrainTransformers-SNN-LLM

Model Performance

Below are the performance metrics of our 3B model on various benchmarks:

General Tasks

DatasetPerformance
MMLU63.2
MMLU-pro33.3
MMLU-redux61.3
BBH54.1
ARC-C54.3
Trurhfulqa47.1
Winogrande68.8
Hellaswag72.8

Math and Science Tasks

DatasetPerformance
GPQA25.3
Theoremqa26.4
MATH41.0
MMLU-stem60.2
GSM8K76.3

Coding and Multilingual Tasks

DatasetPerformance
HumanEval40.5
HumanEval+34.6
MBPP55.0
MBPP+47.5
MultiPL-E39.6
Multi-Exam52.6
Multi-Understanding73.9
Multi-Mathematics47.1
Multi-Translation28.2

Usage

Generate Text

import torch
from transformers import AutoTokenizer, BrainGPTForCausalLM

model_path = "/path/to/your/model"
model = BrainGPTForCausalLM.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

def generate_text(messages, max_new_tokens=50):
    text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
    model_inputs = tokenizer([text], return_tensors="pt").to(device)
    
    with torch.no_grad():
        generated_ids = model.generate(**model_inputs, max_new_tokens=max_new_tokens)
    
    generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
    return tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]

# Example usage
messages = [
    {"role": "system", "content": "You are a knowledgeable assistant."},
    {"role": "user", "content": "Explain the Pythagorean theorem."}
]
response = generate_text(messages)
print(response)

Acknowledgments

The model was trained using ANN-Base-Qwen2, with a total of three training stages, including SNN-specific neuron synaptic plasticity training. The technical report is still being prepared. Please note that SNN models do not support ANN fine-tuning techniques. We are currently developing specialized fine-tuning code tools for SNN models. Our open-source model has achieved leading SOTA results, and we welcome your stars.

This repository includes a complete transformers package, which can directly replace the transformers package in your development environment. This allows compatibility with our SNN-Base-LLM without affecting existing usage.

Contributors

LumenScopeAI

30 commits

Brain2nd

1 commits

Languages

Python

99.0%