hf_mirrors/japanese-mpt-7b
Model Introduction
Files & versions
Analysis

Dataset

Japanese subset of the mC4 dataset

Training

Trained for 3000 steps on top of the MPT 7b checkpoint mosaicml/mpt-7b

How to load

Before running this model, please install the following pip package:

pip install einops

To load the model, run the following command.

from openmind import AutoTokenizer, AutoModelForCausalLM, is_torch_npu_available
from openmind_hub import snapshot_download
import torch.nn.functional as F
from torch import Tensor
import openmind
import torch
import argparse
import sys
import time

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default="zhouhui/japanese-mpt-7b",
    )
    args = parser.parse_args()
    return args

def main():
    args = parse_args()
    model_path = args.model_name_or_path

    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"
    start_time = time.time()      
    model = AutoModelForCausalLM.from_pretrained(model_path).to(device)
    tokenizer = AutoTokenizer.from_pretrained(model_path)
    model.eval()

    prompt = """A: こんにちは
        B: こんにちは
        A: 好きなスポーツは何ですか?
        B: サッカーです
        A: 好きな食べ物は何ですか?
        B:"""
    input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
    outputs = model.generate(input_ids=input_ids, max_length=100)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    print(response)
    end_time = time.time()
    print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
    
if __name__ == "__main__":
    main()

To run this model, you may need to load it in a lower precision in order for it to fit onto your GPU. We found for a T4 GPU, it requires loading the model in 8-bit precision. To load the model in 8-bit and 4-bit, please install the following pip packages:

pip install bitsandbytes accelerate

Caution - you will also need enough RAM to load the model. We estimate loading this model requires ~30GB.

Code to load the model in 8 bit
from transformers import AutoModelForCausalLM

model_name = "lightblue/japanese-mpt-7b"
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype='auto',
    load_in_8bit=True,
    trust_remote_code=True
)
Code to load the model in 4 bit
from transformers import AutoModelForCausalLM

model_name = "lightblue/japanese-mpt-7b"
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype='auto',
    load_in_4bit=True,
    trust_remote_code=True
)

How to use

from transformers import AutoTokenizer, pipeline

tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)

prompt = """A: こんにちは
B: こんにちは
A: 好きなスポーツは何ですか?
B: サッカーです
A: 好きな食べ物は何ですか?
B:"""

pipe(prompt, temperature=0, do_sample=False, return_full_text=False, max_new_tokens=32)
# [{"generated_text": " カレーです
# A: 好きな色は何ですか?
# B: 赤です"}]