MatCaviar commited on
Commit
6211e23
·
verified ·
1 Parent(s): 6ec7fbe

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +129 -3
README.md CHANGED
@@ -1,3 +1,129 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+ # AlchemistCoder: Harmonizing and Eliciting Code Capability by Hindsight Tuning on Multi-source Data
5
+
6
+ [[🤗 HuggingFace](https://huggingface.co/internlm/AlchemistCoder-DS-6.7B)]
7
+ [[📃 Paper](https://arxiv.org/abs/xxxxx)]
8
+ [[🌐 Project Page](https://internlm.github.io/AlchemistCoder/)]
9
+
10
+
11
+ ## ✨ Highlights
12
+ > **Abstract:** *Open-source Large Language Models (LLMs) and their specialized variants, particularly Code LLMs, have recently delivered impressive performance. However, previous Code LLMs are typically fine-tuned on single-source data with limited quality and diversity, which may insufficiently elicit the potential of pre-trained Code LLMs. In this paper, we present AlchemistCoder, a series of Code LLMs with enhanced code generation and generalization capabilities fine-tuned on multi-source data. To achieve this, we pioneer to unveil inherent conflicts among the various styles and qualities in multi-source code corpora and introduce data-specific prompts with hindsight relabeling, termed AlchemistPrompts, to harmonize different data sources and instruction-response pairs. Additionally, we propose incorporating the data construction process into the fine-tuning data as code comprehension tasks, including instruction evolution, data filtering, and code review. Extensive experiments demonstrate that AlchemistCoder holds a clear lead among all models of the same size (6.7B/7B) and rivals or even surpasses larger models (15B/33B/70B), showcasing the efficacy of our method in refining instruction-following capabilities and advancing the boundaries of code intelligence.*
13
+
14
+ - **AlchemistPrompts**: Designed as data-specific prompts for harmonizing inherent conflicts in multi-source data and mitigating the instruction/response misalignment at a fined-grained level.
15
+ - **Code Comprehenstion Tasks**: Sourced from the process of data construction, consisting of instruction evolution, data filtering, and code review.
16
+ - **Harmonized Multi-source Data**: Instruction tuned on 200M tokens, including 6 types of high-quality data.
17
+ - **Superior Model Performance**: Surpassing all the open-source models of the same size (6.7/7B), and rivaling or even beating larger models (15B/33B/70B/ChatGPT) on 6 code benchmarks.
18
+ - **Advanced generic capabilities**: Demonstrated by the significant improvements on MMLU, BBH, and GSM8K.
19
+
20
+
21
+ ## 🚀 Quick Start
22
+ ```python
23
+ import torch
24
+ from transformers import AutoModelForCausalLM, AutoTokenizer
25
+
26
+ tokenizer = AutoTokenizer.from_pretrained("internlm/AlchemistCoder-DS-6.7B", trust_remote_code=True)
27
+ model = AutoModelForCausalLM.from_pretrained("internlm/AlchemistCoder-DS-6.7B", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
28
+ model = model.eval()
29
+
30
+ input_text = "Implement the Dijkstra algorithm in Python"
31
+ inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
32
+ outputs = model.generate(**inputs, max_length=128)
33
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
34
+ ```
35
+
36
+ The above code will generate the following result:
37
+ ```python
38
+ import heapq
39
+
40
+ def dijkstra(graph, start, end):
41
+ """
42
+ Find the shortest path between two nodes in a graph using Dijkstra's algorithm.
43
+
44
+ Args:
45
+ graph (dict): A dictionary representing the graph, where the keys are nodes and the values are dictionaries
46
+ containing the neighboring nodes and their edge weights.
47
+ start: The starting node.
48
+ end: The target node.
49
+
50
+ Returns:
51
+ list: The shortest path from the start node to the target node as a list of nodes.
52
+
53
+ Raises:
54
+ ValueError: If either the start or end node is not present in the graph.
55
+
56
+ """
57
+
58
+ # Check if start and end nodes are in the graph
59
+ if start not in graph:
60
+ raise ValueError("Start node is not present in the graph.")
61
+ if end not in graph:
62
+ raise ValueError("End node is not present in the graph.")
63
+
64
+ # Initialize the distance dictionary with infinite distances for all nodes
65
+ distances = {node: float('inf') for node in graph}
66
+
67
+ # Set the distance of the start node to 0
68
+ distances[start] = 0
69
+
70
+ # Initialize the heap with the start node
71
+ heap = [(0, start)]
72
+
73
+ # Initialize the previous dictionary to keep track of the path
74
+ previous = {}
75
+
76
+ while heap:
77
+ # Pop the node with the smallest distance from the heap
78
+ current_distance, current_node = heapq.heappop(heap)
79
+
80
+ # If the current node is the end node, we have found the shortest path
81
+ if current_node == end:
82
+ # Reconstruct the path by following the previous nodes
83
+ path = []
84
+ while current_node in previous:
85
+ path.append(current_node)
86
+ current_node = previous[current_node]
87
+ path.append(start)
88
+ # Reverse the path to get the correct order
89
+ return path[::-1]
90
+
91
+ # Iterate over the neighboring nodes and update their distances
92
+ for neighbor, weight in graph[current_node].items():
93
+ new_distance = current_distance + weight
94
+ # If a shorter path is found, update the distance and previous node
95
+ if new_distance < distances[neighbor]:
96
+ distances[neighbor] = new_distance
97
+ previous[neighbor] = current_node
98
+ heapq.heappush(heap, (new_distance, neighbor))
99
+
100
+ # If there is no path between the start and end nodes, return an empty list
101
+ return []
102
+ ```
103
+
104
+ > The `dijkstra` function takes three arguments: `graph`, `start`, and `end`. The `graph` argument is a dictionary representing the graph, where the keys are nodes and the values are dictionaries containing the neighboring nodes and their edge weights. The `start` argument is the starting node, and the `end` argument is the target node.
105
+ > The function first checks if the start and end nodes are present in the graph. If either node is not present, a `ValueError` is raised.
106
+ > The function then initializes a `distances` dictionary with infinite distances for all nodes. It sets the distance of the start node to 0. It also initializes a heap with the start node and a `previous` dictionary to keep track of the path.
107
+ > The algorithm then iterates over the nodes in the heap. For each node, it checks if it is the end node. If it is, the function reconstructs the path by following the previous nodes and returns the shortest path as a list of nodes in the correct order.
108
+ > If the current node is not the end node, the algorithm iterates over its neighboring nodes and updates their distances if a shorter path is found. It also updates the `previous` dictionary to keep track of the path.
109
+ > If there is no path between the start and end nodes, the function returns an empty list.
110
+ > Note that this implementation assumes that the graph is a directed graph, and it uses a heap data structure to efficiently select the node with the smallest distance at each step.
111
+
112
+
113
+ ## 🧪 Evaluation and Fine-tune
114
+ Please refer to [**AlchemistCoder**](https://github.com/InternLM/AlchemistCoder) and [**InternLM**](https://github.com/InternLM/InternLM/tree/main).
115
+
116
+ ## 😃 Acknowledgments
117
+ *AlchemistCoder* is built with [**InternLM**](https://github.com/InternLM) and [**OpenCompass**](https://github.com/open-compass). Thanks for their awesome work!
118
+
119
+ ## 📧 Contact
120
+ If you have any questions, please create an issue on this repository or contact us at:
121
122
123
+
124
+ ## 🌟 Citation
125
+ If you find our work useful, please consider citing:
126
+
127
+ ```bibtex
128
+
129
+ ```