yujiepan / mamba2-tiny-random

huggingface.co
Total runs: 95
24-hour runs: 0
7-day runs: 6
30-day runs: 15
Model's Last Updated: October 08 2024
text-generation

Introduction of mamba2-tiny-random

Model Details of mamba2-tiny-random

This model is for debugging. It is randomly initialized using the config from mistralai/Mamba-Codestral-7B-v0.1 but with smaller size.

Codes:

import os

import torch

from huggingface_hub import create_repo, upload_folder
from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    GenerationConfig,
    Mamba2Config,
    pipeline,
    set_seed,
)

model_id = "mistralai/Mamba-Codestral-7B-v0.1"
repo_id = "yujiepan/mamba2-tiny-random"
save_path = f"/tmp/{repo_id}"

os.system(f'rm -rf {save_path}')

config = Mamba2Config.from_pretrained(model_id)
config.use_cache = True
config.num_hidden_layers = 2
config.num_heads = 8
config.head_dim = 4
config.hidden_size = 8
config.expand = 4
config.intermediate_size = 32
config.state_size = 8
config.n_groups = 2

assert config.intermediate_size == \
    config.hidden_size * config.expand == config.num_heads * config.head_dim
assert config.num_heads // config.n_groups > 0
assert config.num_heads % 8 == 0

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
tokenizer.save_pretrained(save_path)

model = AutoModelForCausalLM.from_config(
    config, torch_dtype=torch.bfloat16,
    trust_remote_code=True,
)
model.generation_config = GenerationConfig.from_pretrained(
    model_id,
    trust_remote_code=True,
)

set_seed(42)
with torch.no_grad():
    for name, p in sorted(model.named_parameters()):
        print(name, p.shape)
        torch.nn.init.uniform_(p, -0.5, 0.5)

model.save_pretrained(save_path)

pipe = pipeline(
    "text-generation",
    model=save_path,
    device="cuda",
    trust_remote_code=True,
    max_new_tokens=20,
)
print(pipe("Hello World!"))

create_repo(repo_id, exist_ok=True)
upload_folder(repo_id=repo_id, folder_path=save_path, repo_type='model')

Runs of yujiepan mamba2-tiny-random on huggingface.co

95
Total runs
0
24-hour runs
1
3-day runs
6
7-day runs
15
30-day runs

More Information About mamba2-tiny-random huggingface.co Model

mamba2-tiny-random huggingface.co

mamba2-tiny-random huggingface.co is an AI model on huggingface.co that provides mamba2-tiny-random's model effect (), which can be used instantly with this yujiepan mamba2-tiny-random model. huggingface.co supports a free trial of the mamba2-tiny-random model, and also provides paid use of the mamba2-tiny-random. Support call mamba2-tiny-random model through api, including Node.js, Python, http.

mamba2-tiny-random huggingface.co Url

https://huggingface.co/yujiepan/mamba2-tiny-random

yujiepan mamba2-tiny-random online free

mamba2-tiny-random huggingface.co is an online trial and call api platform, which integrates mamba2-tiny-random's modeling effects, including api services, and provides a free online trial of mamba2-tiny-random, you can try mamba2-tiny-random online for free by clicking the link below.

yujiepan mamba2-tiny-random online free url in huggingface.co:

https://huggingface.co/yujiepan/mamba2-tiny-random

mamba2-tiny-random install

mamba2-tiny-random is an open source model from GitHub that offers a free installation service, and any user can find mamba2-tiny-random on GitHub to install. At the same time, huggingface.co provides the effect of mamba2-tiny-random install, users can directly use mamba2-tiny-random installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

mamba2-tiny-random install url in huggingface.co:

https://huggingface.co/yujiepan/mamba2-tiny-random

Url of mamba2-tiny-random

mamba2-tiny-random huggingface.co Url

Provider of mamba2-tiny-random huggingface.co

yujiepan
ORGANIZATIONS

Other API from yujiepan