Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
sync commit
  • Loading branch information
eduand-alvarez committed Aug 26, 2024
2 parents aad91eb + 02dc74d commit 1a9f326
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 546 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# AI Innovation Bridge

Welcome to our AI Innovation Bridge repo! This repo contains reference solutions, hackathon sample code, workshop content, and more!
Welcome to our AI Innovation Bridge repo! This repo contains reference solutions, hackathon sample code, workshop content, and more!

## Table of Contents
- [hackathons](hackathons)
- [solutions](solutions)
- [workshops](workshops)
- [utilities](utilities)

Enjoy!
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fastapi
uvicorn
scikit-learn==1.0.1
tensorflow==2.11.1
scikit-learn==1.5.0
tensorflow==2.12.1
numpy
pandas==1.4.1
pydantic
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ modin==0.15.2
numpy==1.23.2
pandas==1.4.3
plotly==5.10.0
scikit-learn==1.1.2
scikit-learn==1.5.0
scikit-learn-intelex==2021.6.3
seaborn==0.11.2
xgboost==1.6.1
xgboost==1.6.1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
accelerate==0.28.0
einops==0.7.0
intel-extension-for-pytorch==2.1.100
intel-extension-for-pytorch==2.2.0
intel-extension-for-transformers==1.2.2
neural-speed==0.2
neural-compressor==2.5
torch==2.1.1
transformers==4.34.1
torch==2.2.0
transformers==4.38.0
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,21 @@
},
"outputs": [],
"source": [
"!source /opt/intel/oneapi/setvars.sh #comment out if not running on Intel Developer Cloud Jupyter\n",
"!pip install git+https://github.com/huggingface/transformers\n",
"!pip install torch==2.1.0\n",
"!pip install tiktoken==0.5.2"
"import sys\n",
"!{sys.executable} -m pip install transformers==4.44.0 --no-warn-script-location > /dev/null\n",
"!{sys.executable} -m pip install torch==2.1.0 --no-warn-script-location > /dev/null\n",
"!{sys.executable} -m pip install tiktoken==0.5.2 --no-warn-script-location > /dev/null"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "54f36f4e-9605-4e99-9154-f2e76488ec25",
"metadata": {},
"outputs": [],
"source": [
"# force restart kernel to pull latest environment\n",
"exit()"
]
},
{
Expand All @@ -61,7 +72,7 @@
"metadata": {},
"source": [
"#### Model Loading\n",
"Here, we load the model and tokenizer from Hugging Face. We're using `AutoModelForCausalLM` and `AutoTokenizer` from the `transformers` library to load \"stabilityai/stablelm-2-1_6b\", a causal language model. The `trust_remote_code` flag is set to `True` for remote code execution, and `torch_dtype` is set to \"auto\" for automatic precision setting, optimizing performance on the underlying hardware..\n"
"Here, we load the model and tokenizer from Hugging Face. We're using `AutoModelForCausalLM` and `AutoTokenizer` from the `transformers` library to load \"microsoft/Phi-3.5-mini-instruct\", a causal language model. The `trust_remote_code` flag is set to `True` for remote code execution, and `torch_dtype` is set to \"auto\" for automatic precision setting, optimizing performance on the underlying hardware..\n"
]
},
{
Expand All @@ -74,10 +85,13 @@
"outputs": [],
"source": [
"# Load model directly\n",
"\n",
"model = \"microsoft/Phi-3.5-mini-instruct\"\n",
"\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
"tokenizer = AutoTokenizer.from_pretrained(\"stabilityai/stablelm-2-1_6b\", trust_remote_code=True)\n",
"tokenizer = AutoTokenizer.from_pretrained(model, trust_remote_code=True)\n",
"model = AutoModelForCausalLM.from_pretrained(\n",
" \"stabilityai/stablelm-2-1_6b\",\n",
" model,\n",
" trust_remote_code=True,\n",
" torch_dtype=\"auto\",\n",
")"
Expand Down Expand Up @@ -137,17 +151,7 @@
" torch_dtype=torch.bfloat16,\n",
" trust_remote_code=True,\n",
" device_map=\"auto\",\n",
" )\n",
"\n",
"sequences = generator( \n",
" \"I love learning to code...\",\n",
" max_length=64,\n",
" do_sample=True,\n",
" top_k=3,\n",
" temperature=0.70,\n",
" top_p=0.95,\n",
" num_return_sequences=1,\n",
" eos_token_id=tokenizer.eos_token_id,)"
" )"
]
},
{
Expand All @@ -159,6 +163,24 @@
"In the final cell, we iterate through the sequences generated by our pipeline and print them out. This step is crucial for visualizing the outputs of our text generation pipeline, allowing us to evaluate the model's performance in generating coherent and contextually relevant text..\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d13188b2-4585-4524-8b4d-14450fef8bac",
"metadata": {},
"outputs": [],
"source": [
"sequences = generator( \n",
" \"I love learning to code...\",\n",
" max_length=64,\n",
" do_sample=True,\n",
" top_k=3,\n",
" temperature=0.70,\n",
" top_p=0.95,\n",
" num_return_sequences=1,\n",
" eos_token_id=tokenizer.eos_token_id,)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -189,7 +211,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "base",
"display_name": "Base",
"language": "python",
"name": "base"
},
Expand All @@ -203,7 +225,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"source": [
"# Leveraging Intel Optimizations with Hugging Face for Enhanced Model Performance\n",
"\n",
"<img src=\"https://www.developer-tech.com/wp-content/uploads/sites/3/2023/08/intel-pytorch-foundation-ai-development-artificial-intelligence-coding-programming-machine-learning.jpg\" alt=\"Alt Text\" style=\"width: 400px;\"/>\n",
"\n",
"Welcome to this developer-centric workshop where we explore the synergies between Hugging Face and Intel Extension for PyTorch (IPEX). This notebook serves as an introduction to utilizing IPEX for fine-tuning a pre-trained model, specifically focusing on the `distilbert-base-uncased` model for multi-class emotion classification in text.\n",
"\n",
"## Why This is Important\n",
Expand Down Expand Up @@ -44,12 +42,23 @@
},
"outputs": [],
"source": [
"!source /opt/intel/oneapi/setvars.sh #comment out if not running on Intel Developer Cloud Jupyter\n",
"!pip install transformers==4.35.2\n",
"!pip install torch==2.1.0\n",
"!pip install intel_extension_for_pytorch==2.1.0\n",
"!pip install datasets==2.16.1\n",
"!pip install accelerate==0.26.0"
"import sys\n",
"!{sys.executable} -m pip install transformers==4.44.0 --no-warn-script-location > /dev/null\n",
"!{sys.executable} -m pip install torch==2.2.0 --no-warn-script-location > /dev/null\n",
"!{sys.executable} -m pip install intel_extension_for_pytorch==2.2.0 --no-warn-script-location > /dev/null\n",
"!{sys.executable} -m pip install datasets==2.16.1 --no-warn-script-location > /dev/null\n",
"!{sys.executable} -m pip install accelerate==0.32.0 --no-warn-script-location > /dev/null"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0cb853ac-e1a6-41dc-9b68-da66b010e578",
"metadata": {},
"outputs": [],
"source": [
"# force restart kernel to pull latest environment\n",
"exit()"
]
},
{
Expand Down Expand Up @@ -177,14 +186,14 @@
"# Define training arguments\n",
"training_args = TrainingArguments(\n",
" output_dir=\"./results\",\n",
" learning_rate=2e-5,\n",
" learning_rate=2e-3,\n",
" per_device_train_batch_size=16,\n",
" per_device_eval_batch_size=16,\n",
" num_train_epochs=1,\n",
" weight_decay=0.01,\n",
" evaluation_strategy=\"epoch\",\n",
" bf16=True, \n",
" use_ipex=True,\n",
" bf16=True, #False to train at FP32\n",
" use_ipex=True, #False to train w/o IPEX\n",
" no_cuda=True,\n",
")\n",
"\n",
Expand Down Expand Up @@ -288,7 +297,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "base",
"display_name": "Base",
"language": "python",
"name": "base"
},
Expand All @@ -302,7 +311,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 1a9f326

Please sign in to comment.