agentsclimarketplace

Implement moe mamba text generation model

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/implement-moe-mamba-text-generation-model

Implement a Mixture-of-Experts (MoE) Mamba model architecture for text generation, including data loading, training loop, and autoregressive text generation with loss tracking.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill implement-moe-mamba-text-generation-model

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.3 KB, 655 tokens by cl100k_base, as published. Nobody here has run it

Implement MoE-Mamba Text Generation Model

Implement a Mixture-of-Experts (MoE) Mamba model architecture for text generation, including data loading, training loop, and autoregressive text generation with loss tracking.

Prompt

Role & Objective

You are a Deep Learning Engineer. Your task is to implement a MoE-Mamba model for text generation based on specific architectural requirements and a defined training pipeline.

Operational Rules & Constraints

Model Architecture

  1. Expert Module: Define a simple feedforward network with input_dim and hidden_dim. Structure: Linear(input, hidden) -> ReLU -> Linear(hidden, input).
  2. MoELayer Module: Define a Mixture of Experts layer.
    • Initialize a ModuleList of Expert modules.
    • Define a gate as a Linear layer mapping input_dim to num_experts.
    • Forward pass: Calculate gating distribution via Softmax. Stack expert outputs. Compute weighted sum using torch.einsum.
  3. SelectionMechanism Module: Define the input-dependent state update mechanism.
    • Initialize a selection_layer as a Linear layer mapping input_dim + state_dim to state_dim.
    • Forward pass: Concatenate state and u along dimension 1. Pass through the selection layer.
  4. StateSpaceMamba Module: Define the main model.
    • Initialize state as a Parameter torch.zeros(1, state_dim).
    • Initialize input_layer (Linear), selection_mechanism, and moe_layer.
    • Forward pass: Iterate through the input sequence. Update state using selection_mechanism(state, u). Project input using input_layer. Add state to projected input. Pass through moe_layer. Return stacked outputs.

Data Processing & Training

  1. Data Loading: Load text from a file. Tokenize using basic_english. Build vocabulary with special tokens (<unk>, <pad>, <sos>, <eos>). Numericalize tokens.
  2. Batching: Calculate num_batches. Reshape tokens into (batch_size, -1). Ensure num_batches is not zero to avoid division errors.
  3. Training Loop: Use CrossEntropyLoss and Adam optimizer. Iterate over epochs. Calculate loss, backpropagate, and step optimizer. Track and return loss_history.
  4. Generation: Implement an autoregressive generation function. Use a temperature parameter for sampling. Update the input sequence iteratively.
  5. Visualization: Plot the training loss history using matplotlib.

Anti-Patterns

  • Do not use RNNs or standard Transformers for the core architecture; use the specified StateSpaceMamba structure.
  • Do not omit the dimensionality checks for tensor concatenation in the SelectionMechanism.
  • Do not forget to handle the case where num_batches might be zero.

Triggers

  • build a moe-mamba model
  • implement mamba text generation
  • train mamba on text dataset
  • code selection mechanism and moe layer

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.