Skip to content

Convert python samples to use UV with uv.lock and .toml files also remove conda dependency #2610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
},
{
"cell_type": "markdown",
"id": "0d6d8fb4-983b-417f-88c3-dc2747de3d4a",
"id": "415587fc",
"metadata": {},
"source": [
"### Model Training on CPU(Optional, if device is CPU) "
Expand All @@ -305,7 +305,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1ff86b79-9bc8-4e6e-8d43-b2cfa1eb500f",
"id": "69093d44",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -518,7 +518,7 @@
},
{
"cell_type": "markdown",
"id": "87063fd1",
"id": "7f5ef9d6",
"metadata": {},
"source": [
"Model Evaluation on CPU(optional, if trained on CPU)"
Expand All @@ -527,7 +527,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8a59b600",
"id": "c84c5b1e",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -616,25 +616,7 @@
]
}
],
"metadata": {
"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.9.15"
},
"vscode": {
"interpreter": {
"hash": "ed6ae0d06e7bec0fef5f1fb38f177ceea45508ce95c68ed2f49461dd6a888a39"
}
}
},
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[project]
name = "intel_pytorch_gpu_inference_optimization_with_amp"
version = "0.1.0"
description = "This sample illustrates how to use AMP BFLOAT16 in PyTorch on Intel dGPU"
authors = [
{name = "Copyright © 2023 Intel Corporation"}
]
license = {text = "MIT"}
readme = "README.md"
requires-python = ">=3.11,<3.12"
dependencies = [
"deepspeed==0.15.4",
"intel-extension-for-pytorch==2.5.10",
"matplotlib>=3.10.1",
"neural-compressor==3.1.1",
"numpy==1.26.4",
"oneccl-bind-pt==2.5.0",
"requests>=2.32.3",
"torch==2.5.1",
"torchaudio==2.5.1",
"torchvision==0.20.1",
"tqdm>=4.67.1",
]


[dependency-groups]
dev = [
"jupyter>=1.1.1",
]

[[tool.uv.index]]
url = "https://pytorch-extension.intel.com/release-whl/stable/xpu/cn/"
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
{
"id": "intel pytorch gpu inference optimization with amp",
"steps": [
"source /intel/oneapi/intelpython/bin/activate",
"source activate pytorch-gpu",
"pip install -r requirements.txt",
"pip install jupyter ipykernel",
"python -m ipykernel install --user --name=pytorch-gpu",
"python IntelPyTorch_GPU_InferenceOptimization_with_AMP.py"
]
"pip install uv==0.6.3",
"uv sync",
"uv run jupyter nbconvert --ExecutePreprocessor.enabled=True --to notebook IntelPyTorch_GPU_InferenceOptimization_with_AMP.ipynb"
]
}
]
]
},
"expertise": "Code Optimization"
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@
"id": "2f7486b6",
"metadata": {},
"outputs": [],
"source": [
"os.environ[\"ONEDNN_MAX_CPU_ISA\"] = \"AVX512_CORE_BF16\""
]
"source": []
},
{
"cell_type": "code",
Expand All @@ -152,6 +150,13 @@
" training_time: the time in seconds it takes to train the model\n",
" \"\"\"\n",
"\n",
" if amx:\n",
" # Set the environment variable to enable Intel® AMX\n",
" os.environ[\"ONEDNN_MAX_CPU_ISA\"] = \"AVX512_CORE_AMX\"\n",
" else:\n",
" # Set the environment variable to disable Intel® AMX\n",
" os.environ[\"ONEDNN_MAX_CPU_ISA\"] = \"AVX512_CORE_BF16\"\n",
"\n",
" # Initialize the model \n",
" model = torchvision.models.resnet50()\n",
" model = model.to(memory_format=torch.channels_last)\n",
Expand Down Expand Up @@ -265,18 +270,7 @@
"outputs": [],
"source": [
"print(\"Training model with BF16 with AVX512\")\n",
"!python pytorch_training_avx512_bf16.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a9bd6dec",
"metadata": {},
"outputs": [],
"source": [
"# Record the training time for BF16 using AVX512\n",
"bf16_avx512_training_time = None #TODO: enter in training time"
"bf16_avx512_training_time = trainModel(train_loader, amx=False, modelName=\"bf16_withAmx\", dataType=\"bf16\")"
]
},
{
Expand All @@ -287,7 +281,7 @@
"outputs": [],
"source": [
"print(\"Training model with BF16 with Intel® AMX\")\n",
"bf16_amx_training_time = trainModel(train_loader, modelName=\"bf16_withAmx\", dataType=\"bf16\")"
"bf16_amx_training_time = trainModel(train_loader, amx=True, modelName=\"bf16_noAmx\", dataType=\"bf16\")"
]
},
{
Expand Down Expand Up @@ -389,30 +383,7 @@
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.10 64-bit (microsoft store)",
"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.8.10"
},
"vscode": {
"interpreter": {
"hash": "ed6ae0d06e7bec0fef5f1fb38f177ceea45508ce95c68ed2f49461dd6a888a39"
}
}
},
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[project]
name = "intelpytorch-trainingoptimizations-amx-bf16"
version = "0.1.0"
description = "This sample illustrates how to train a PyTorch model using Advanced Matrix Extensions Bfloat16"
authors = [
{name = "Copyright © 2020 Intel Corporation"}
]
license = {text = "MIT"}
readme = "README.md"
requires-python = ">=3.11,<3.12"
dependencies = [
"deepspeed==0.15.4",
"intel-extension-for-pytorch==2.5.0",
"ipykernel>=6.29.5",
"ipywidgets>=8.1.5",
"jupyter>=1.1.1",
"matplotlib>=3.10.1",
"neural-compressor==3.1.1",
"numpy==1.26.4",
"onnxruntime==1.19.2",
"py-cpuinfo>=9.0.0",
"setuptools>=75.8.2",
"torch==2.5.0",
"torchaudio==2.5.0",
"torchvision>=0.20.0",
"transformers>=4.49.0",
]

[tool.uv.sources]
torch = { index = "pytorch" }
torchvision = { index = "pytorch" }

[[tool.uv.index]]
name = "pytorch"
# Required URL for the index.
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[[tool.uv.index]]
url = "https://software.repos.intel.com/python/pypi"

[dependency-groups]
dev = [
"jupyter>=1.1.1",
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
{
"id": "intel amx bf16 training",
"steps": [
"source /intel/oneapi/intelpython/bin/activate",
"conda activate pytorch",
"python -m pip install -r requirements.txt",
"python -m ipykernel install --user --name=pytorch",
"python pytorch_training_avx512_bf16.py",
"python pytorch_training_amx_bf16.py",
"jupyter nbconvert --ExecutePreprocessor.enabled=True --ExecutePreprocessor.kernel_name=pytorch --to notebook IntelPyTorch_TrainingOptimizations_AMX_BF16.ipynb"
"pip install uv==0.6.3",
"uv sync",
"uv run jupyter nbconvert --ExecutePreprocessor.enabled=True --to notebook IntelPyTorch_TrainingOptimizations_AMX_BF16.ipynb"
]
}
]
Expand Down
Loading