Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jnesfield authored Sep 16, 2024
1 parent 2722ab6 commit 11b7f92
Showing 1 changed file with 218 additions and 0 deletions.
218 changes: 218 additions & 0 deletions mmfreelm/notebooks/matmul_free_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"id": "450a195b-8d1d-4683-9365-ba6b50b98b1c",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.\n",
"The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"In a shocking finding, scientist discovered a herd of unicorns living in a remote, icy mountain in the Russian Arctic.\n",
"\n"
]
}
],
"source": [
"import os\n",
"os.environ[\"TOKENIZERS_PARALLELISM\"] = \"false\"\n",
"import mmfreelm\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
"#Change here to our open-sourced model\n",
"model_name = 'ridger/MMfreeLM-1.3B'\n",
"tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
"model = AutoModelForCausalLM.from_pretrained(model_name).cuda().half()\n",
"input_prompt = \"In a shocking finding, scientist discovered a herd of unicorns living in a remote, \"\n",
"input_ids = tokenizer(input_prompt, return_tensors=\"pt\").input_ids.cuda()\n",
"outputs = model.generate(input_ids, max_length=100, do_sample=True, top_p=0.4, temperature=0.6)\n",
"print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "bbcc7945-9ca0-4016-8d5d-b070ac7ea8ce",
"metadata": {},
"outputs": [],
"source": [
"model.save_pretrained(model_name)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "9ebccae6-8f9f-4e5f-a0e6-b04083244f9e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"In a shocking finding, scientist discovered a herd of unicorns living in a remote, 19th century German village. The herd was believed to be a result of a disease that killed all of the animals for generations. The herd was believed to have been wiped out by a disease that killed all animals for generations. But a team of scientists has discovered that it was actually a disease that was caused by an ancient disease that killed all animals for generations. The disease was called \"the black death\". It killed more than 60 million people in Europe in the 14th century. The disease was so deadly that it killed more people than all wars and plagues combined for more than a thousand years.\n"
]
}
],
"source": [
"# Example input\n",
"input_prompt = \"In a shocking finding, scientist discovered a herd of unicorns living in a remote, \"\n",
"input_ids = tokenizer(input_prompt, return_tensors=\"pt\").input_ids.cuda()\n",
"\n",
"# Generate output\n",
"outputs = model.generate(input_ids, max_length=150, do_sample=True, top_p=0.4, temperature=0.6)\n",
"print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "81abf0d2-61aa-4f20-81b0-472efc525139",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"What can you tell me about gpt models?\n",
"I have a question about gpt models. I have a question about gpt models. What can I tell about them?\n",
"I have a question about gpt models. What can I tell about them?\n",
"I have a question about gpt models. What can I tell about them?\n",
"I have a question about gpt models. What can I tell about them?\n",
"I have a question about gpt models. What can I tell about them?\n",
"I have a question about gpt models. What can I tell about them?\n",
"I have a question about gpt models. What can I tell about them?\n",
"I have a question about gpt models. What\n"
]
}
],
"source": [
"# Example input\n",
"input_prompt = \"What can you tell me about gpt models?\"\n",
"input_ids = tokenizer(input_prompt, return_tensors=\"pt\").input_ids.cuda()\n",
"\n",
"# Generate output\n",
"outputs = model.generate(input_ids, max_length=150, do_sample=True, top_p=0.4, temperature=0.6)\n",
"print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "961b4bc8-640b-4bc4-97fe-0320a2e700ab",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Write me code in python to make a list in a list in a list in python in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list in a list\n"
]
}
],
"source": [
"# Example input\n",
"input_prompt = \"Write me code in python to make a list\"\n",
"input_ids = tokenizer(input_prompt, return_tensors=\"pt\").input_ids.cuda()\n",
"\n",
"# Generate output\n",
"outputs = model.generate(input_ids, max_length=150, do_sample=True, top_p=0.4, temperature=0.6)\n",
"print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "966dd1f7-7c49-429e-8e03-48aca236c3cd",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Spiking neural networks can do awesome things! For example, they can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can learn from a huge amount of data, can\n"
]
}
],
"source": [
"# Example input\n",
"input_prompt = 'Spiking neural networks can do awesome things!'\n",
"input_ids = tokenizer(input_prompt, return_tensors=\"pt\").input_ids.cuda()\n",
"\n",
"# Generate output\n",
"outputs = model.generate(input_ids, max_length=150, do_sample=True, top_p=0.4, temperature=0.6)\n",
"print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dd5e9c41-b861-4516-95f1-fa474664e9ec",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 11b7f92

Please sign in to comment.