csharp mpt instruct 7b llm .net

Try it

C#

Code for use form .Net CSharp on CPU that runs on Windows, Mac M and Linux

Python

import torch
import transformers
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
tokenizer.pad_token = tokenizer.eos_token

device = torch.device("cuda")
model_name = "Nethermind/Mpt-Instruct-DotNet-S"
config = transformers.AutoConfig.from_pretrained(model_name, trust_remote_code=True)
config.init_device = device
config.max_seq_len = 1024 
config.attn_config['attn_impl'] = 'torch'
config.use_cache = False

model = transformers.AutoModelForCausalLM.from_pretrained(
	model_name,
	config=config,
	torch_dtype=torch.bfloat16,
	trust_remote_code=True,
	ignore_mismatched_sizes=True,
	# load_in_8bit=True # when low on GPU memory
)
model.eval()

INSTRUCTION_KEY = "### Instruction:"
RESPONSE_KEY = "### Response:"
PROMPT_FOR_GENERATION_FORMAT = """{system}
{instruction_key}
{instruction}
{response_key}
""".format(
    system="{system}",
    instruction_key=INSTRUCTION_KEY,
    instruction="{instruction}",
    response_key=RESPONSE_KEY
)

def give_answer(instruction="Create a loop over [0, 6, 7 , 77] that prints its contentrs", system="You are an experienced .Net C# developer. Below is an instruction that describes a task. Write a response that completes the request providing detailed explanations with code examples.", ):
    question = PROMPT_FOR_GENERATION_FORMAT.format(system=system, instruction=instruction)
    input_tokens = tokenizer.encode(question ,return_tensors='pt')               
	model.generate(input_tokens.to(device), max_new_tokens=min(512, 1024 - input_tokens.shape[1]), do_sample=False, top_k=1, top_p=0.95)
    outputs = output_loop(tokenized_question)
    answer = tokenizer.batch_decode(outputs, skip_special_tokens=True)
    print(answer[0])

Training

Finetuned for CSharp mosaicml/mpt-7b-instruct. Max context length is restricted to 1024 tokens.

Sources

data contained (most data was around 500 tokens long < 1000, except large code files):

Contents