abacaj commited on
Commit
9a03cb9
1 Parent(s): 90bf1fc

add readme

Browse files
Files changed (1) hide show
  1. README.md +87 -0
README.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: bsd-3-clause
3
+ ---
4
+ # CodeGen (CodeGen-NL 16B)
5
+
6
+ ## Sharded version of codegen
7
+
8
+ This model was sharded using torch.float16. Use the code below to load this model, configure the device_map for your GPU/CPU split.
9
+
10
+ ```python
11
+ def load_model_sharded():
12
+ config = AutoConfig.from_pretrained("abacaj/codegen-16B-nl-sharded")
13
+ tokenizer = AutoTokenizer.from_pretrained("abacaj/codegen-16B-nl-sharded")
14
+
15
+ with init_empty_weights():
16
+ model = AutoModelForCausalLM.from_config(config)
17
+
18
+ device_map = infer_auto_device_map(
19
+ model,
20
+ max_memory={
21
+ 0: "20GiB",
22
+ "cpu": "110GiB",
23
+ },
24
+ dtype=torch.float16,
25
+ no_split_module_classes=["CodeGenBlock"])
26
+
27
+ model = load_checkpoint_and_dispatch(
28
+ model,
29
+ dtype=torch.float16,
30
+ checkpoint="sharded",
31
+ device_map=device_map,
32
+ ).eval()
33
+
34
+ return model, tokenizer
35
+ ```
36
+
37
+ ## Model description
38
+
39
+ CodeGen is a family of autoregressive language models for **program synthesis** from the paper: [A Conversational Paradigm for Program Synthesis](https://arxiv.org/abs/2203.13474) by Erik Nijkamp, Bo Pang, Hiroaki Hayashi, Lifu Tu, Huan Wang, Yingbo Zhou, Silvio Savarese, Caiming Xiong. The models are originally released in [this repository](https://github.com/salesforce/CodeGen), under 3 pre-training data variants (`NL`, `Multi`, `Mono`) and 4 model size variants (`350M`, `2B`, `6B`, `16B`).
40
+
41
+ The checkpoint included in this repository is denoted as **CodeGen-NL 16B** in the paper, where "NL" means it is pre-trained on the Pile and "16B" refers to the number of trainable parameters.
42
+
43
+ ## Training data
44
+
45
+ This checkpoint (CodeGen-NL 16B) was pre-trained on [the Pile](https://github.com/EleutherAI/the-pile), a large-scale curated dataset created by [EleutherAI](https://www.eleuther.ai/). Parts of the dataset include code data.
46
+
47
+ ## Training procedure
48
+
49
+ CodeGen was trained using cross-entropy loss to maximize the likelihood of sequential inputs.
50
+ The family of models are trained using multiple TPU-v4-512 by Google, leveraging data and model parallelism.
51
+ See Section 2.3 of the [paper](https://arxiv.org/abs/2203.13474) for more details.
52
+
53
+ ## Evaluation results
54
+
55
+ We evaluate our models on two code generation benchmark: HumanEval and MTPB. Please refer to the [paper](https://arxiv.org/abs/2203.13474) for more details.
56
+
57
+
58
+ ## Intended Use and Limitations
59
+
60
+ As an autoregressive language model, CodeGen is capable of extracting features from given natural language and programming language texts, and calculating the likelihood of them.
61
+ However, the model is intended for and best at **program synthesis**, that is, generating executable code given English prompts, where the prompts should be in the form of a comment string. The model can complete partially-generated code as well.
62
+
63
+ ## How to use
64
+
65
+ This model can be easily loaded using the `AutoModelForCausalLM` functionality:
66
+
67
+ ```python
68
+ from transformers import AutoTokenizer, AutoModelForCausalLM
69
+ tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen-16B-nl")
70
+ model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen-16B-nl")
71
+
72
+ text = "def hello_world():"
73
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
74
+ generated_ids = model.generate(input_ids, max_length=128)
75
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
76
+ ```
77
+
78
+ ## BibTeX entry and citation info
79
+
80
+ ```bibtex
81
+ @article{Nijkamp2022ACP,
82
+ title={A Conversational Paradigm for Program Synthesis},
83
+ author={Nijkamp, Erik and Pang, Bo and Hayashi, Hiroaki and Tu, Lifu and Wang, Huan and Zhou, Yingbo and Savarese, Silvio and Xiong, Caiming},
84
+ journal={arXiv preprint},
85
+ year={2022}
86
+ }
87
+ ```