|
@@ -15,7 +15,10 @@
|
|
"\n",
|
|
"\n",
|
|
"We will adapt the BLOOM model for the classification task using the [SST-2 dataset](https://nlp.stanford.edu/sentiment/). This dataset is a binary classification task, where the goal is to predict whether a sentence is positive or negative. The SST-2 dataset is a subset of the Stanford Sentiment Treebank, and it is available in the [Hugging Face Datasets](https://huggingface.co/datasets) library.\n",
|
|
"We will adapt the BLOOM model for the classification task using the [SST-2 dataset](https://nlp.stanford.edu/sentiment/). This dataset is a binary classification task, where the goal is to predict whether a sentence is positive or negative. The SST-2 dataset is a subset of the Stanford Sentiment Treebank, and it is available in the [Hugging Face Datasets](https://huggingface.co/datasets) library.\n",
|
|
"\n",
|
|
"\n",
|
|
- "To open this notebook in colab: [](https://colab.research.google.com/github/bigscience-workshop/petals/blob/main/examples/prompt-tuning-sst2.ipynb)"
|
|
|
|
|
|
+ "To use this notebook in Colab:\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "1. Follow this link: [](https://colab.research.google.com/github/bigscience-workshop/petals/blob/main/examples/prompt-tuning-sst2.ipynb)\n",
|
|
|
|
+ "2. Go to **Runtime** -> **Change runtime type** and select the GPU accelerator."
|
|
]
|
|
]
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -33,18 +36,8 @@
|
|
"metadata": {},
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"outputs": [],
|
|
"source": [
|
|
"source": [
|
|
- "import subprocess\n",
|
|
|
|
- "import sys\n",
|
|
|
|
- "\n",
|
|
|
|
"!pip install git+https://github.com/bigscience-workshop/petals\n",
|
|
"!pip install git+https://github.com/bigscience-workshop/petals\n",
|
|
- "!pip install datasets wandb\n",
|
|
|
|
- "\n",
|
|
|
|
- "IN_COLAB = 'google.colab' in sys.modules\n",
|
|
|
|
- "if IN_COLAB: # Remove CUDA binaries on CPU-only colabs to not confuse bitsandbytes\n",
|
|
|
|
- " try:\n",
|
|
|
|
- " subprocess.check_output([\"nvidia-smi\", \"-L\"])\n",
|
|
|
|
- " except subprocess.CalledProcessError as e:\n",
|
|
|
|
- " subprocess.run(\"rm -r /usr/local/cuda/lib64\", shell=True)"
|
|
|
|
|
|
+ "!pip install datasets wandb"
|
|
]
|
|
]
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -84,14 +77,12 @@
|
|
"metadata": {},
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"outputs": [],
|
|
"source": [
|
|
"source": [
|
|
- "MODEL_NAME = ... # select model you like\n",
|
|
|
|
- "INITIAL_PEERS = [...] # add your peers adresses here, like \"/ip4/192.168.1.2/tcp/31000/p2p/Qma....\"\n",
|
|
|
|
|
|
+ "MODEL_NAME = \"bigscience/bloom-petals\" # select model you like\n",
|
|
"NUM_PREFIX_TOKENS = 16\n",
|
|
"NUM_PREFIX_TOKENS = 16\n",
|
|
"DEVICE = 'cpu'\n",
|
|
"DEVICE = 'cpu'\n",
|
|
- "BATCH_SIZE = 4\n",
|
|
|
|
|
|
+ "BATCH_SIZE = 16\n",
|
|
"LR = 1e-2\n",
|
|
"LR = 1e-2\n",
|
|
"WEIGHT_DECAY = 0.0\n",
|
|
"WEIGHT_DECAY = 0.0\n",
|
|
- "NUM_SAMPLES = 1000\n",
|
|
|
|
"NUM_EPOCHS = 3\n",
|
|
"NUM_EPOCHS = 3\n",
|
|
"SEED = 42\n",
|
|
"SEED = 42\n",
|
|
"MODEL_MAX_LENGTH = 64\n",
|
|
"MODEL_MAX_LENGTH = 64\n",
|
|
@@ -117,9 +108,8 @@
|
|
"tokenizer.padding_side = 'right'\n",
|
|
"tokenizer.padding_side = 'right'\n",
|
|
"tokenizer.model_max_length = MODEL_MAX_LENGTH\n",
|
|
"tokenizer.model_max_length = MODEL_MAX_LENGTH\n",
|
|
"model = DistributedBloomForSequenceClassification.from_pretrained(\n",
|
|
"model = DistributedBloomForSequenceClassification.from_pretrained(\n",
|
|
- " MODEL_NAME, \n",
|
|
|
|
- " initial_peers=INITIAL_PEERS, \n",
|
|
|
|
- " pre_seq_len=NUM_PREFIX_TOKENS, \n",
|
|
|
|
|
|
+ " MODEL_NAME,\n",
|
|
|
|
+ " pre_seq_len=NUM_PREFIX_TOKENS,\n",
|
|
" tuning_mode=TUNING_MODE\n",
|
|
" tuning_mode=TUNING_MODE\n",
|
|
").to(DEVICE)"
|
|
").to(DEVICE)"
|
|
]
|
|
]
|
|
@@ -251,7 +241,6 @@
|
|
" project=\"bloom-sst-2\",\n",
|
|
" project=\"bloom-sst-2\",\n",
|
|
" config={\n",
|
|
" config={\n",
|
|
" \"num_epochs\": NUM_EPOCHS,\n",
|
|
" \"num_epochs\": NUM_EPOCHS,\n",
|
|
- " \"num_samples\": NUM_SAMPLES,\n",
|
|
|
|
" \"batch_size\": BATCH_SIZE,\n",
|
|
" \"batch_size\": BATCH_SIZE,\n",
|
|
" \"learning_rate\": LR,\n",
|
|
" \"learning_rate\": LR,\n",
|
|
" \"weight_decay\": WEIGHT_DECAY,\n",
|
|
" \"weight_decay\": WEIGHT_DECAY,\n",
|
|
@@ -291,7 +280,7 @@
|
|
],
|
|
],
|
|
"metadata": {
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"kernelspec": {
|
|
- "display_name": "Python 3.8.10 64-bit",
|
|
|
|
|
|
+ "display_name": "Python 3.8.12 ('bloom-demo')",
|
|
"language": "python",
|
|
"language": "python",
|
|
"name": "python3"
|
|
"name": "python3"
|
|
},
|
|
},
|
|
@@ -305,11 +294,11 @@
|
|
"name": "python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"pygments_lexer": "ipython3",
|
|
- "version": "3.6.9"
|
|
|
|
|
|
+ "version": "3.8.12"
|
|
},
|
|
},
|
|
"vscode": {
|
|
"vscode": {
|
|
"interpreter": {
|
|
"interpreter": {
|
|
- "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
|
|
|
|
|
|
+ "hash": "175c31e15dd38a7dfc9eb4117a9e428ffb6063af97d545b6bfba4d874ecc4bb8"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|