Skip to content
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

Bump PyTorch to 2.1 #502

Merged
merged 28 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
356ef2a
bump to torch 2.1
JingyaHuang Mar 4, 2024
c81dc3f
skip weights/neff sep test for torch 2.*
JingyaHuang Mar 4, 2024
b9c5325
Merge branch 'main' into bump-to-torch2
JingyaHuang Apr 8, 2024
9e71b27
fix style
JingyaHuang Apr 8, 2024
3eb01fc
fix style
JingyaHuang Apr 8, 2024
f0bda6b
chore(tgi): use pytorch 2
dacorvo Apr 8, 2024
0e96959
test(tgi): update sampling tests expectations
dacorvo Apr 8, 2024
adf7a76
test(tgi): update sampling tests expectations
dacorvo Apr 8, 2024
aecb643
fix(tgi): python3-dev is now required
dacorvo Apr 8, 2024
4701f99
test(tgi): update sampling expectations in integration test
dacorvo Apr 8, 2024
7db7a67
Merge branch 'bump-to-torch2' of https://github.com/huggingface/optim…
JingyaHuang Apr 10, 2024
d708143
Merge branch 'main' into bump-to-torch2
JingyaHuang Apr 10, 2024
fa76578
try fix CIs
JingyaHuang Apr 10, 2024
93eb8af
try+1
JingyaHuang Apr 10, 2024
8462b07
try+1
JingyaHuang Apr 10, 2024
61a5571
try again
JingyaHuang Apr 10, 2024
2ad128e
restore weights/neff sep test
JingyaHuang Apr 10, 2024
89eb09d
Fix gradient checkpoiting for PT 2.1 (and maybe for before as well)
michaelbenayoun Apr 11, 2024
b486187
Merge branch 'bump-to-torch2' of github.com:huggingface/optimum-neuro…
michaelbenayoun Apr 11, 2024
4b2aebb
Fix LLama-2 tracing
michaelbenayoun Apr 11, 2024
b4bd78f
Merge branch 'main' into bump-to-torch2
michaelbenayoun Apr 11, 2024
dbe50bb
Fix distributed tests
michaelbenayoun Apr 12, 2024
ee4678c
Remove XRT server related code
michaelbenayoun Apr 12, 2024
1706415
Merge branch 'main' into bump-to-torch2
michaelbenayoun Apr 12, 2024
a3375d5
test(tgi): update expectations for PT2.1
dacorvo Apr 12, 2024
27a1e38
perf(tgi): update results
dacorvo Apr 12, 2024
971d902
fix: style
dacorvo Apr 12, 2024
6ef1857
tools: remove invalid check
dacorvo Apr 12, 2024
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
1 change: 0 additions & 1 deletion optimum/exporters/neuron/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ def export_models(
output_path.parent.mkdir(parents=True, exist_ok=True)

try:

# TODO: Remove after the weights/neff separation compilation of sdxl is patched by a neuron sdk release: https://github.com/aws-neuron/aws-neuron-sdk/issues/859
if not inline_weights_to_neff and getattr(sub_neuron_config, "is_sdxl", False):
logger.warning(
Expand Down
1 change: 0 additions & 1 deletion optimum/neuron/accelerate/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def patch_accelerate_is_tpu_available():


def create_patched_finfo(xla_downcast_bf16: bool = False, use_amp: bool = False, xla_use_bf16: bool = False):

def patched_finfo(dtype):
if xla_downcast_bf16 or use_amp or xla_use_bf16:
return _ORIG_TORCH_FINFO(torch.bfloat16)
Expand Down
2 changes: 0 additions & 2 deletions optimum/neuron/modeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@
from ..exporters.neuron import NeuronDefaultConfig

if is_neuron_available():

NEURON_COMPILER_TYPE = "neuron-cc"
NEURON_COMPILER_VERSION = get_neuroncc_version()

if is_neuronx_available():

NEURON_COMPILER_TYPE = "neuronx-cc"
NEURON_COMPILER_VERSION = get_neuronxcc_version()

Expand Down
1 change: 0 additions & 1 deletion optimum/neuron/training_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def __post_init__(self):

@cached_property
def _setup_devices(self) -> "torch.device":

requires_backends(self, ["torch"])
logger.info("PyTorch: setting up devices")
NeuronAcceleratorState._reset_state()
Expand Down
8 changes: 8 additions & 0 deletions optimum/neuron/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union

import torch
from packaging import version
from transformers import AutoFeatureExtractor, AutoProcessor, AutoTokenizer, CLIPProcessor, PretrainedConfig
from transformers.modeling_utils import _add_variant
from transformers.utils import (
Expand All @@ -43,6 +44,7 @@
from ...utils import is_diffusers_available, logging
from .import_utils import is_torch_neuronx_available, is_torch_xla_available
from .require_utils import requires_safetensors, requires_torch_xla
from .version_utils import get_torch_version


if is_torch_neuronx_available():
Expand Down Expand Up @@ -547,6 +549,12 @@ def replace_weights(
"""
Replaces the weights in a Neuron Model with weights from another model, the original neuron model should have separated weights(by setting `inline_weights_to_neff=Talse` during the tracing).
"""
torch_version = get_torch_version()
if version.parse(torch_version) >= version.parse("2.0.0"):
raise RuntimeError(
"Weights Neff separation is not yet supported by Neuron SDK for PyTorch 2.*. You can downgrade your PyTorch version to 1.13.1."
)

if isinstance(weights, torch.nn.Module):
weights = weights.state_dict()

Expand Down
9 changes: 9 additions & 0 deletions optimum/neuron/utils/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

import unittest

from packaging import version

from .import_utils import is_neuron_available, is_neuronx_available
from .version_utils import get_torch_version


def requires_neuron(test_case):
Expand All @@ -33,6 +36,12 @@ def requires_neuron_or_neuronx(test_case):
)(test_case)


def requires_pytorch_1_13(test_case):
return unittest.skipUnless(
version.parse(get_torch_version()) < version.parse("2.0.0"), "test requires PyTorch < 2.0.0"
)(test_case)


JingyaHuang marked this conversation as resolved.
Show resolved Hide resolved
def is_trainium_test(test_case):
test_case = requires_neuronx(test_case)
try:
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"neuronx": [
"wheel",
"neuronx-cc==2.13.66.0",
"torch-neuronx==1.13.1.1.14.0",
"torch-neuronx==2.1.2.2.1.0",
"transformers-neuronx==0.10.0.21",
"torch==1.13.1.*",
"torchvision==0.14.*",
"torch==2.1.2.*",
"torchvision==0.16.*",
"neuronx_distributed==0.7.0",
],
"diffusers": ["diffusers ~= 0.26.1", "peft"],
Expand Down
4 changes: 2 additions & 2 deletions tests/inference/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
pipeline,
)
from optimum.neuron.utils import NEURON_FILE_NAME, is_neuron_available, is_neuronx_available
from optimum.neuron.utils.testing_utils import is_inferentia_test, requires_neuronx
from optimum.neuron.utils.testing_utils import is_inferentia_test, requires_neuronx, requires_pytorch_1_13
from optimum.utils import (
CONFIG_NAME,
logging,
Expand Down Expand Up @@ -150,6 +150,7 @@ def test_save_compiler_intermediary_files(self):
os.listdir(save_path)
self.assertTrue(os.path.exists(neff_path))

@requires_pytorch_1_13
@requires_neuronx
def test_decouple_weights_neff_and_replace_weight(self):
with tempfile.TemporaryDirectory() as tempdir:
Expand Down Expand Up @@ -404,7 +405,6 @@ def test_sentence_transformers_dyn_bs(self, model_arch):
@parameterized.expand(["clip"], skip_on_empty=True)
@requires_neuronx
def test_sentence_transformers_clip(self, model_arch):

# Neuron model with dynamic batching
model_id = SENTENCE_TRANSFORMERS_MODEL_NAMES[model_arch]
input_shapes = {
Expand Down
3 changes: 2 additions & 1 deletion text-generation-inference/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
gnupg2 \
wget \
python3-dev \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

Expand All @@ -102,7 +103,7 @@ ENV PATH="/opt/bin/:/opt/aws/neuron/bin:${PATH}"

RUN pip3 install \
neuronx-cc==2.13.66.0 \
torch-neuronx==1.13.1.1.14.0 \
torch-neuronx==2.1.2.2.1.0 \
transformers-neuronx==0.10.0.21 \
--extra-index-url=https://pip.repos.neuron.amazonaws.com

Expand Down
2 changes: 1 addition & 1 deletion text-generation-inference/integration-tests/test_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def test_model_single_request(tgi_client):
seed=42,
decoder_input_details=True,
)
assert "The purpose of the current post is" in response.generated_text
assert "A lot of researchers are trying to explain what it is" in response.generated_text


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion text-generation-inference/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create_request(
top_k: int = 50,
top_p: float = 0.9,
temperature: float = 1.0,
seed: int = 0,
seed: int = 42,
repetition_penalty: float = 1.0,
):
parameters = NextTokenChooserParameters(
Expand Down
6 changes: 3 additions & 3 deletions text-generation-inference/tests/test_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def test_info(model_path):
],
[
"It was a bright cold day in April, and the clocks were striking thirteen.",
198,
"\n",
383,
" The",
True,
],
],
Expand All @@ -69,7 +69,7 @@ def test_prefill(input_text, token_id, token_text, do_sample, batch_size, model_
[
"It was a bright cold day in April, and the clocks were striking thirteen.",
20,
"\n\nAt 11:45 a.m. a small group of friends gathered outside the hotel to",
" The sun was set just three miles south of the city. There were no houses, just shops,",
True,
],
],
Expand Down
2 changes: 1 addition & 1 deletion text-generation-inference/tests/test_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_prefill(input_text, token_id, token_text, do_sample, batch_size, model_
[
"It was a bright cold day in April, and the clocks were striking thirteen.",
20,
" It was time to return to the village of Uckfield to face the fury of the evil",
" It was the start of the new spring, a time when nature woke from her winter slumber",
True,
],
],
Expand Down
Loading