CoolFace
Modelpublic

Nethermind/Mpt-Instruct-DotNet-S

sourceHugging Facecc-by-sa-3.0updated 3y agoView on Hugging Face
1likes84downloads
README.md90 linesDownload Raw Back to root
1---2license: cc-by-sa-3.03language:4- en5pipeline_tag: text-generation6tags:7- csharp8- mpt9- instruct10- 7b11- llm12- .net13---14 15## Try it16 17### C#18Code for [use form .Net CSharp on CPU](https://github.com/NethermindEth/Mpt-Instruct-DotNet-S) that runs on Windows, Mac M and Linux19 20### Python21```python22import torch23import transformers24from transformers import AutoTokenizer25 26tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")27tokenizer.pad_token = tokenizer.eos_token28 29device = torch.device("cuda")30model_name = "Nethermind/Mpt-Instruct-DotNet-S"31config = transformers.AutoConfig.from_pretrained(model_name, trust_remote_code=True)32config.init_device = device33config.max_seq_len = 1024 34config.attn_config['attn_impl'] = 'torch'35config.use_cache = False36 37model = transformers.AutoModelForCausalLM.from_pretrained(38	model_name,39	config=config,40	torch_dtype=torch.bfloat16,41	trust_remote_code=True,42	ignore_mismatched_sizes=True,43	# load_in_8bit=True # when low on GPU memory44)45model.eval()46 47INSTRUCTION_KEY = "### Instruction:"48RESPONSE_KEY = "### Response:"49PROMPT_FOR_GENERATION_FORMAT = """{system}50{instruction_key}51{instruction}52{response_key}53""".format(54    system="{system}",55    instruction_key=INSTRUCTION_KEY,56    instruction="{instruction}",57    response_key=RESPONSE_KEY58)59 60def 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.", ):61    question = PROMPT_FOR_GENERATION_FORMAT.format(system=system, instruction=instruction)62    input_tokens = tokenizer.encode(question ,return_tensors='pt')               63	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)64    outputs = output_loop(tokenized_question)65    answer = tokenizer.batch_decode(outputs, skip_special_tokens=True)66    print(answer[0])67 68```69 70 71## Training72Finetuned for CSharp [mosaicml/mpt-7b-instruct](https://huggingface.co/mosaicml/mpt-7b-instruct). Max context length is restricted to 1024 tokens.73 74- 'Loss': 0.256045166015625 on 300k CSharp-related records75- 'Loss': 0.095714599609375 on 50k specific short prompts76 77## Sources78data contained (most data was around 500 tokens long < 1000, except large code files):79- codeparrot/github-code C# ("mit", "Apache-2.0", "Bsd-3-clause", "Bsd-2-clause", "Cc0-1.0", "Unlicense", "isc")80- 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)81- documented static functions 72k82- SO 5q_5answer + 5q_5best (CC BY-SA 4.0) 70k83- Dotnet wiki (30k, rendered out from [github repo](https://github.com/microsoft/dotnet), see also removed, GPT-4 generated short question to each file)84- All NM Static Functions and Tests (from [nethermind client repo](https://github.com/NethermindEth/nethermind) documented and described via GPT-4 (4k)85- GPT-4 questions, GPT-3.5 answers for CSharp: Short Q->Code, Explain Code X > Step-By-Step (35k)86- GPT-4 questions, GPT-3.5 answers for nethermind client interface `IEthRpcModule `: Short Q->Code, Explain Code X -> Step-By-Step (7k)87 88## Contents89- HF compatible model90- GGML compatible quantisations (f16, q8, q5)