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.

  • 'Loss': 0.256045166015625 on 300k CSharp-related records
  • 'Loss': 0.095714599609375 on 50k specific short prompts

Sources

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

  • codeparrot/github-code C# ("mit", "Apache-2.0", "Bsd-3-clause", "Bsd-2-clause", "Cc0-1.0", "Unlicense", "isc")
  • raw data Plain .cs files randomly cut at the 60-80% in the instruction, and we ask the network to continue last 40-20% (76k)
  • documented static functions 72k
  • SO 5q_5answer + 5q_5best (CC BY-SA 4.0) 70k
  • Dotnet wiki (30k, rendered out from github repo, see also removed, GPT-4 generated short question to each file)
  • All NM Static Functions and Tests (from nethermind client repo documented and described via GPT-4 (4k)
  • GPT-4 questions, GPT-3.5 answers for CSharp: Short Q->Code, Explain Code X > Step-By-Step (35k)
  • GPT-4 questions, GPT-3.5 answers for nethermind client interface IEthRpcModule : Short Q->Code, Explain Code X -> Step-By-Step (7k)

Contents

  • HF compatible model
  • GGML compatible quantisations (f16, q8, q5)
Downloads last month
1,190
Inference Examples
Inference API (serverless) does not yet support model repos that contain custom code.