File size: 5,388 Bytes
dd6a935
 
df4cb31
dd6a935
 
a8b22ac
dd6a935
19b517d
dd6a935
 
 
 
 
a8b22ac
dd6a935
19b517d
dd6a935
 
 
 
19b517d
dd6a935
 
 
a8b22ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19b517d
a8b22ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd6a935
 
 
19b517d
a8b22ac
dd6a935
19b517d
dd6a935
19b517d
dd6a935
a8b22ac
 
 
 
 
dd6a935
 
a8b22ac
dd6a935
a8b22ac
dd6a935
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
---
library_name: transformers
license: apache-2.0
---

# Model Card for mAInframer-1

LLM for the COBOL programming language.

## Model Details

### Model Description

mAInframer is a series of models with different parameter counts: 7b, 13b, 34b.

These models are pretrained on code (CodeLlama base models) and fine-tuned on COBOL code.


## Uses

This model can be used for code completion and fill-in-the middle (COBOL).

## How to Get Started with the Model

Model loading:

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("bloopai/mAInframer-7b", device_map="cuda", torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained("codellama/CodeLlama-7b-hf")
```

### Completion:

```python
prompt = '''       IDENTIFICATION DIVISION.
       PROGRAM-ID.  SUM-OF-CUBES.
       ENVIRONMENT DIVISION.
       
       INPUT-OUTPUT SECTION.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01 STEP         PIC S9(10).
       01 CUBE         PIC 9(7).
       01 CUBE-SUM     PIC 9(7) VALUE 0.

       LINKAGE SECTION.

       01 LINKED-ITEMS.
           05 L-MAX-STEP PIC S9(10).
           05 RESULT PIC S9(10).

      * 
      * Given an integer number, return the sum of the of all the integers below it.
      * 
      * Example:
      * 
      * sum_of_cubes(3) == 1**3 + 2**3 == 9
      * sum_of_cubes(5) == 100
      *  

      * Store the result in the RESULT variable and mark the end of your program with END PROGRAM
'''
inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=False).to("cuda")
outputs = model.generate(inputs, max_new_tokens=250, use_cache=True, do_sample=False, repetition_penalty=1.1)
print(self.tokenizer.decode(outputs[0]))
```

Result:
```cobol
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  SUM-OF-CUBES.
       ENVIRONMENT DIVISION.
       
       INPUT-OUTPUT SECTION.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01 STEP         PIC S9(10).
       01 CUBE         PIC 9(7).
       01 CUBE-SUM     PIC 9(7) VALUE 0.

       LINKAGE SECTION.

       01 LINKED-ITEMS.
           05 L-MAX-STEP PIC S9(10).
           05 RESULT PIC S9(10).

      * 
      * Given an integer number, return the sum of the of all the integers below it.
      * 
      * Example:
      * 
      * sum_of_cubes(3) == 1**3 + 2**3 == 9
      * sum_of_cubes(5) == 100
      *  

      * Store the result in the RESULT variable and mark the end of your program with END PROGRAM

       PROCEDURE DIVISION USING LINKED-ITEMS.
           MOVE L-MAX-STEP TO STEP.
           PERFORM VARYING STEP FROM 1 BY 1 UNTIL STEP > L-MAX-STEP
               COMPUTE CUBE = STEP ** 3
               ADD CUBE TO CUBE-SUM
           END-PERFORM.
           DISPLAY CUBE-SUM.
           MOVE CUBE-SUM TO RESULT.
           GOBACK.
           
       END PROGRAM SUM-OF-CUBES.
```

### Infilling

Follow the format: `<PRE>prefix<SUF>suffix<MID>`

To complete `PROCEDURE DIVISION` and infill `WORKING STORAGE SECTION.` to solve [COBOLEval](https://github.com/BloopAI/COBOLEval) problems:

```python
prompt = '''<PRE>       IDENTIFICATION DIVISION.
       PROGRAM-ID.  SUM-OF-CUBES.
       ENVIRONMENT DIVISION.
       
       INPUT-OUTPUT SECTION.

       DATA DIVISION.<SUF>

       LINKAGE SECTION.

       01 LINKED-ITEMS.
           05 L-MAX-STEP PIC S9(10).
           05 RESULT PIC S9(10).

      * 
      * Given an integer number, return the sum of the of all the integers below it.
      * 
      * Example:
      * 
      * sum_of_cubes(3) == 1**3 + 2**3 == 9
      * sum_of_cubes(5) == 100
      *  

      * Store the result in the RESULT variable and mark the end of your program with END PROGRAM'''
```

Result:
```cobol
<PRE>       IDENTIFICATION DIVISION.
       PROGRAM-ID. MAX-ELEMENT.

       ENVIRONMENT DIVISION.
       
       INPUT-OUTPUT SECTION.

       DATA DIVISION.<SUF>
       LINKAGE SECTION.

       01 LINKED-ITEMS.
           05 L-L OCCURS 100 TIMES INDEXED BY NI PIC S9(10).
           05 RESULT PIC S9(10).

      * Return maximum element in the list.
      * >>> max_element([1, 2, 3])
      * 3
      * >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
      * 123
      * 

      * Store the result in the RESULT variable and mark the end of your program with END PROGRAM

       PROCEDURE DIVISION USING LINKED-ITEMS.
           MOVE ZERO TO WS-MAX-VALUE.
           PERFORM VARYING NI FROM 1 BY 1 UNTIL NI > 100
               IF L-L (NI) > WS-MAX-VALUE THEN
                   MOVE L-L (NI) TO WS-MAX-VALUE
               END-IF
           END-PERFORM.
           DISPLAY 'THE MAXIMUM ELEMENT IS: ' WS-MAX-VALUE.
           MOVE WS-MAX-VALUE TO RESULT.
           GOBACK.
           
       END PROGRAM MAX-ELEMENT.

<MID>
       WORKING-STORAGE SECTION.
       
       01 WS-MAX-VALUE PIC S9(10) VALUE ZERO.

```

## Training Details

Base model: CodeLlama
Finetuning type: LoRA

### Metrics

[COBOLEval](https://github.com/BloopAI/COBOLEval) is an adaptation of HumanEval where the problems are translated to COBOL.

| **Model**            | CobolEval (pass@1) | 
|----------------------|--------------------|
| **mAInframer-7b**    | 6.16   | 
| **mAInframer-13b**   | 8.90   |
| **mAInframer-34b**   | 10.27  |


## Citation 

[Blog post]() 


## Model Card Contact

[More Information Needed]