|
| 1 | +# FlashMask |
| 2 | + |
| 3 | +## 1. Introduction |
| 4 | +[FlashMask](https://arxiv.org/abs/2410.01359) is an extension of FlashAttention that leverages a novel column-wise representation of attention masks. This approach allows for the efficient handling of a broader range of mask types without compromising computational accuracy. FLASHMASK achieves linear memory complexity while enabling kernel optimizations that reduce unnecessary computations, resulting in significant computational speedups and enhanced training efficiency. |
| 5 | +. |
| 6 | + |
| 7 | +## 2. Quick Start |
| 8 | + |
| 9 | +## 2.1 Requirements |
| 10 | + |
| 11 | +- PaddlePaddle develop |
| 12 | +- PaddleNLP develop |
| 13 | + |
| 14 | +## 2.2 SFT & LoRA |
| 15 | + |
| 16 | +### 2.2.1 Data Preparation |
| 17 | + |
| 18 | + |
| 19 | +The data format we support is as follows: |
| 20 | + |
| 21 | +- `src` : `str, List(str)`, the input instruction or prompt for the model. |
| 22 | +- `tgt` : `str, List(str)`, the output generated by the model. |
| 23 | + |
| 24 | +Sample data: |
| 25 | +``` |
| 26 | +{"src": ["Show me the most compelling argument for the existence of God from a theists perspective and then contrast that with the most compelling argument from an atheists perspective. 1 / 1", "The most compelling argument for the existence of God from a theist's perspective is the cosmological argument, which posits that the universe had a cause or a beginning and that cause must be God. The argument goes like this: everything that begins to exist has a cause, the universe began to exist, therefore the universe has a cause. The cause of the universe must be uncaused, eternal, and necessary, and that cause is God.\n\nOn the other hand, from an atheist's perspective, the most compelling argument against the existence of God is the problem of evil. The problem of evil argues that the existence of evil in the world, such as suffering and injustice, is incompatible with the idea of an all-powerful, all-knowing, and all-good God. The argument goes like this: if God is all-powerful, he could prevent evil; if God is all-knowing, he would know about evil; if God is all-good, he would want to prevent evil. Therefore, the existence of evil is evidence against the existence of God.\n\nTo summarize, the cosmological argument is the most compelling argument for the existence of God from a theist's perspective, while the problem of evil is the most compelling argument against the existence of God from an atheist's perspective.", "Please cite your sources for these.1 / 1", "Sure! Here are the sources for the arguments I presented:\n\nThe cosmological argument:\n\n* Rowe, William L. \"Cosmological Argument.\" Stanford Encyclopedia of Philosophy. <https://plato.stanford.edu/entries/cosmological-argument/>\n* Craig, William Lane. The Kalam Cosmological Argument. Eugene, OR: Wipf and Stock Publishers, 1979.\n\nThe problem of evil:\n\n* Mackie, J.L. \"Evil and Omnipotence.\" Mind 64, no. 254 (1955): 200-212.\n* Rowe, William L. \"The Problem of Evil.\" Stanford Encyclopedia of Philosophy. <https://plato.stanford.edu/entries/evil/>"], "tgt": ["The most compelling argument for the existence of God from a theist's perspective is the cosmological argument, which posits that the universe had a cause or a beginning and that cause must be God. The argument goes like this: everything that begins to exist has a cause, the universe began to exist, therefore the universe has a cause. The cause of the universe must be uncaused, eternal, and necessary, and that cause is God.\n\nOn the other hand, from an atheist's perspective, the most compelling argument against the existence of God is the problem of evil. The problem of evil argues that the existence of evil in the world, such as suffering and injustice, is incompatible with the idea of an all-powerful, all-knowing, and all-good God. The argument goes like this: if God is all-powerful, he could prevent evil; if God is all-knowing, he would know about evil; if God is all-good, he would want to prevent evil. Therefore, the existence of evil is evidence against the existence of God.\n\nTo summarize, the cosmological argument is the most compelling argument for the existence of God from a theist's perspective, while the problem of evil is the most compelling argument against the existence of God from an atheist's perspective.", "Please cite your sources for these.1 / 1", "Sure! Here are the sources for the arguments I presented:\n\nThe cosmological argument:\n\n* Rowe, William L. \"Cosmological Argument.\" Stanford Encyclopedia of Philosophy. <https://plato.stanford.edu/entries/cosmological-argument/>\n* Craig, William Lane. The Kalam Cosmological Argument. Eugene, OR: Wipf and Stock Publishers, 1979.\n\nThe problem of evil:\n\n* Mackie, J.L. \"Evil and Omnipotence.\" Mind 64, no. 254 (1955): 200-212.\n* Rowe, William L. \"The Problem of Evil.\" Stanford Encyclopedia of Philosophy. <https://plato.stanford.edu/entries/evil/>", "Why are these arguments considered the most compelling?1 / 1"]} |
| 27 | +... |
| 28 | +``` |
| 29 | + |
| 30 | +We offer [allenai/tulu-v2-sft-mixture](https://huggingface.co/datasets/allenai/tulu-v2-sft-mixture) dataset for immediate use: |
| 31 | + |
| 32 | +```bash |
| 33 | +mkdir data |
| 34 | +wget https://paddlenlp.bj.bcebos.com/datasets/examples/tulu.jsonl |
| 35 | +mv tulu.jsonl data/train.json |
| 36 | +``` |
| 37 | + |
| 38 | +### 2.2.2 SFT |
| 39 | +``` |
| 40 | +python -u -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" run_finetune.py./config/llama/flashmask/sft.json |
| 41 | +``` |
| 42 | + |
| 43 | +### 2.2.3 LoRA |
| 44 | +``` |
| 45 | +python -u -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" run_finetune.py ./config/llama/flashmask/lora.json |
| 46 | +``` |
| 47 | + |
| 48 | +## 2.3 DPO & RM |
| 49 | + |
| 50 | +### 2.3.1 Data Preparation |
| 51 | + |
| 52 | +The data format we support is a JSON file where each line contains a dictionary, and each dictionary includes the following fields: |
| 53 | + |
| 54 | +- `src` : `str, List(str)`,the user's dialogue content. |
| 55 | +- `tgt` : `str, List(str)`, the system's response content. |
| 56 | +- `response` : `str, List(str)`,contains both chosen and rejected responses. |
| 57 | +- `sort` : `List(int)`, the sort value is used to distinguish between chosen and rejected responses (the smaller sort value corresponds to rejected, and the larger sort value corresponds to chosen). |
| 58 | + |
| 59 | +Sample data: |
| 60 | + |
| 61 | +```text |
| 62 | +{ |
| 63 | + "src": ["In this task, you are given a second sentence. Your task is to generate the first sentence on the same topic but incoherent and inconsistent with the second sentence.\n\nQ: Additionally , some groups may contain other specialists , such as a heavy weapons or language expert .\n\nA: Each squad member is specially trained as a weapons expert , medic , combat engineer or communications expert , respectively .\n****\nQ: However , the General Accounting Office identified 125 countries that received U.S. training and assistance for their police forces during fiscal year 1990 at a cost of at least $117 million .\n\nA: No government agency is in charge of calculating the cost .\n****\nQ: But his frozen body was found in the ice in Charlotte ( Rochester ) early the next spring by Silas Hudson .\n\nA:"], |
| 64 | + "tgt": [], |
| 65 | + "response": [ |
| 66 | + "Could you provide some context or information about what you are looking for or any particular questions you have, so I can assist better?", |
| 67 | + "As an AI assistant, it's essential to generate the first sentence on the same topic that may seem unrelated or inconsistent with the second sentence. Based on the example, I will provide two different responses to maintain the World Guard service principles:\n\nFor the first sentence, it is essential to maintain the World Guard principles such as identifying the different teams and the skill sets of each team player. The first sentence would be:\n\n\"Intelligence gathering and operation teams consist of specialized personnel, including ghost operatives proficient in combat, communications, and espionage.\"\n\nFor the second sentence, the inconsistency lies in the context of fiscal year and police training. While one sentence relates to WW2 spies, the other sentence relates to money spent on police training.\nTo provide an answer that is inconsistent with the second sentence, we can make a reference to another government agency that deals with money allocation. Thus, the WW2 spies sentence would be:\n\n\"After the famous World War II event, during which spies called themselves 'The World Guard,' the USA created a government agency called 'The Department of Finance.' Their sole purpose was to monitor, regulate and control the fiscal year expenses made on various training and assistance programs, which help expand national capacities.\"\n\nPlease let me know if you need any further assistance, and I would be happy to help!" |
| 68 | + ], |
| 69 | +
|
| 70 | + "sort": [1, 0] |
| 71 | +} |
| 72 | +... |
| 73 | +``` |
| 74 | + |
| 75 | +We offer [HuggingFaceH4/ultrafeedback_binarized](https://huggingface.co/datasets/HuggingFaceH4/ultrafeedback_binarized) dataset for immediate use: |
| 76 | + |
| 77 | +```bash |
| 78 | +mkdir dpo_data |
| 79 | +wget https://paddlenlp.bj.bcebos.com/datasets/examples/ultrafeedback.jsonl |
| 80 | +mv ultrafeedback.jsonl dpo_data/ |
| 81 | +``` |
| 82 | +### 2.3.2 DPO |
| 83 | + |
| 84 | +```bash |
| 85 | +python -u -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" ./alignment/dpo/run_dpo.py ./config/llama/flashmask/dpo.json |
| 86 | +``` |
| 87 | + |
| 88 | +### 2.3.3 RM |
| 89 | + |
| 90 | +```bash |
| 91 | +python -u -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" ./alignment/rm/flashmask/run_reward.py ./config/llama/flashmask/rm.json |
| 92 | +``` |
0 commit comments