Views
No views yet
replit-code-v1-3b is a 2.7B Causal Language Model focused on Code Completion. The model has been trained on a subset of the Stack Dedup v1.2 dataset.Markdown, Java, JavaScript, Python, TypeScript, PHP, SQL, JSX, reStructuredText, Rust, C, CSS, Go, C++, HTML, Vue, Ruby, Jupyter Notebook, R, Shell
replit-code-v1-3b has been trained on 525B tokens (~195 tokens per parameter).replit-code-v1-3b is powered by state-of-the-art LLM techniques, such as:
Flash Attention for fast training and inference,
AliBi positional embeddings to support variable context length at inference time,
LionW optimizer,
etc.*.py) are licensed under the Apache 2.0 license.einops
sentencepiece
torch
transformers1from transformers import AutoModelForCausalLM
2
3# load model
4model = AutoModelForCausalLM.from_pretrained('replit/replit-code-v1-3b', trust_remote_code=True)flash-attn==0.2.8
triton==2.0.0.dev20221202bfloat16 and use it as follows:1from transformers import AutoModelForCausalLM, AutoConfig
2
3config = AutoConfig.from_pretrained(
4 "replit/replit-code-v1-3b",
5 trust_remote_code=True
6)
7config.attn_config['attn_impl'] = 'triton'
8
9# load model
10model = AutoModelForCausalLM.from_pretrained('replit/replit-code-v1-3b', config=config, trust_remote_code=True)
11model.to(device='cuda:0', dtype=torch.bfloat16)
12
13# forward pass
14x = torch.tensor([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
15x = x.to(device='cuda:0')
16y = model(x)
17trust_remote_code=True is passed to the from_pretrained method because ReplitLM is not a class in the
Transformers library.sentencepiece library to be installed.1from transformers import AutoTokenizer
2
3# load tokenizer
4tokenizer = AutoTokenizer.from_pretrained('replit/replit-code-v1-3b', trust_remote_code=True)
5
6# single input encoding + generation
7x = tokenizer.encode('def hello():\n print("hello world")\n', return_tensors='pt')
8y = model.generate(x)
9
10# decoding, clean_up_tokenization_spaces=False to ensure syntactical correctness
11generated_code = tokenizer.decode(y[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
12print(generated_code)trust_remote_code=True is passed to the from_pretrained method because ReplitLM is not a class in the Transformers library.clean_up_tokenization_spaces=False is meant to avoid removing spaces in the output, because that would affect the syntactical correctness of the generated code.transformers library as follows:1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3tokenizer = AutoTokenizer.from_pretrained('replit/replit-code-v1-3b', trust_remote_code=True)
4model = AutoModelForCausalLM.from_pretrained('replit/replit-code-v1-3b', trust_remote_code=True)
5
6x = tokenizer.encode('def fibonacci(n): ', return_tensors='pt')
7y = model.generate(x, max_length=100, do_sample=True, top_p=0.95, top_k=4, temperature=0.2, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
8
9# decoding, clean_up_tokenization_spaces=False to ensure syntactical correctness
10generated_code = tokenizer.decode(y[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
11print(generated_code)load_in_8bit=True kwarg that uses bitsandbytes under the hood.accelerate
bitsandbytesmodel = AutoModelForCausalLM.from_pretrained("replit/replit-code-v1-3b",
trust_remote_code=True,
device_map="auto",
load_in_8bit=True)device_map='auto' and load_in_8bit=True.load_in_4bit has not been merged into the latest releases for
transformers and accelerate. However you can use it if you install the dependancies the main branches of the published repos:1pip install git+https://github.com/huggingface/accelerate.git
2pip install git+https://github.com/huggingface/transformers.gitmodel = AutoModelForCausalLM.from_pretrained("replit/replit-code-v1-3b",
trust_remote_code=True,
device_map="auto",
load_in_4bit=True)max_tokens to a reasonable value based on your completion use casereturn, def, "```", "\n\n\n" to avoid generating incomplete code when max_tokens is larger than the length of the expected generated code.