From ac64fbb026e8e3ef4d5ed7fcee8ec70708b6952b Mon Sep 17 00:00:00 2001
From: malavhs <malavhs@amazon.com>
Date: Mon, 21 Oct 2024 06:05:35 +0000
Subject: [PATCH 1/4] fix: patch HF PT Inference neuronx latest

---
 dlc_developer_config.toml                                 | 8 ++++----
 .../inference/docker/2.1/py3/sdk2.19.1/Dockerfile.neuronx | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/dlc_developer_config.toml b/dlc_developer_config.toml
index 1f6a589ccc14..6c9cac29a148 100644
--- a/dlc_developer_config.toml
+++ b/dlc_developer_config.toml
@@ -9,7 +9,7 @@ ei_mode = false
 neuron_mode = false
 # Please only set it to true if you are preparing a NEURONX related PR
 # Do remember to revert it back to false before merging any PR (including NEURONX dedicated PR)
-neuronx_mode = false
+neuronx_mode = true
 # Please only set it to true if you are preparing a GRAVITON related PR
 # Do remember to revert it back to false before merging any PR (including GRAVITON dedicated PR)
 graviton_mode = false
@@ -34,10 +34,10 @@ deep_canary_mode = false
 [build]
 # Add in frameworks you would like to build. By default, builds are disabled unless you specify building an image.
 # available frameworks - ["autogluon", "huggingface_tensorflow", "huggingface_pytorch", "huggingface_tensorflow_trcomp", "huggingface_pytorch_trcomp", "pytorch_trcomp", "tensorflow", "mxnet", "pytorch", "stabilityai_pytorch"]
-build_frameworks = []
+build_frameworks = ["huggingface_pytorch"]
 
 # By default we build both training and inference containers. Set true/false values to determine which to build.
-build_training = true
+build_training = false
 build_inference = true
 
 # Set do_build to "false" to skip builds and test the latest image built by this PR
@@ -143,7 +143,7 @@ dlc-pr-tensorflow-2-neuron-inference = ""
 # HuggingFace Inference
 dlc-pr-huggingface-tensorflow-inference = ""
 dlc-pr-huggingface-pytorch-inference = ""
-dlc-pr-huggingface-pytorch-neuron-inference = ""
+dlc-pr-huggingface-pytorch-neuron-inference = "huggingface/pytorch/inference/buildspec-neuronx.yml"
 
 # Stability AI Inference
 dlc-pr-stabilityai-pytorch-inference = ""
diff --git a/huggingface/pytorch/inference/docker/2.1/py3/sdk2.19.1/Dockerfile.neuronx b/huggingface/pytorch/inference/docker/2.1/py3/sdk2.19.1/Dockerfile.neuronx
index 9ce949853440..b14770f89ea6 100644
--- a/huggingface/pytorch/inference/docker/2.1/py3/sdk2.19.1/Dockerfile.neuronx
+++ b/huggingface/pytorch/inference/docker/2.1/py3/sdk2.19.1/Dockerfile.neuronx
@@ -61,8 +61,8 @@ RUN apt-get update \
     libcap-dev \
     gpg-agent \
     libexpat1 \
-    apparmor \
     libarchive13 \
+    apparmor \
  && rm -rf /var/lib/apt/lists/* \
  && rm -rf /tmp/tmp* \
  && apt-get clean

From aa1879044f7c04b947d32be4d608e3a388d8d3af Mon Sep 17 00:00:00 2001
From: malavhs <malavhs@amazon.com>
Date: Mon, 21 Oct 2024 14:17:41 +0000
Subject: [PATCH 2/4] revert dlc_developer_config.toml

---
 dlc_developer_config.toml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/dlc_developer_config.toml b/dlc_developer_config.toml
index 6c9cac29a148..1f6a589ccc14 100644
--- a/dlc_developer_config.toml
+++ b/dlc_developer_config.toml
@@ -9,7 +9,7 @@ ei_mode = false
 neuron_mode = false
 # Please only set it to true if you are preparing a NEURONX related PR
 # Do remember to revert it back to false before merging any PR (including NEURONX dedicated PR)
-neuronx_mode = true
+neuronx_mode = false
 # Please only set it to true if you are preparing a GRAVITON related PR
 # Do remember to revert it back to false before merging any PR (including GRAVITON dedicated PR)
 graviton_mode = false
@@ -34,10 +34,10 @@ deep_canary_mode = false
 [build]
 # Add in frameworks you would like to build. By default, builds are disabled unless you specify building an image.
 # available frameworks - ["autogluon", "huggingface_tensorflow", "huggingface_pytorch", "huggingface_tensorflow_trcomp", "huggingface_pytorch_trcomp", "pytorch_trcomp", "tensorflow", "mxnet", "pytorch", "stabilityai_pytorch"]
-build_frameworks = ["huggingface_pytorch"]
+build_frameworks = []
 
 # By default we build both training and inference containers. Set true/false values to determine which to build.
-build_training = false
+build_training = true
 build_inference = true
 
 # Set do_build to "false" to skip builds and test the latest image built by this PR
@@ -143,7 +143,7 @@ dlc-pr-tensorflow-2-neuron-inference = ""
 # HuggingFace Inference
 dlc-pr-huggingface-tensorflow-inference = ""
 dlc-pr-huggingface-pytorch-inference = ""
-dlc-pr-huggingface-pytorch-neuron-inference = "huggingface/pytorch/inference/buildspec-neuronx.yml"
+dlc-pr-huggingface-pytorch-neuron-inference = ""
 
 # Stability AI Inference
 dlc-pr-stabilityai-pytorch-inference = ""

From 3a9ea2e5c94f94b96f2b17d91422c3dda85688b9 Mon Sep 17 00:00:00 2001
From: malavhs <malavhs@amazon.com>
Date: Tue, 22 Oct 2024 00:59:32 +0000
Subject: [PATCH 3/4] patch libarchive13

---
 dlc_developer_config.toml                                 | 8 ++++----
 .../docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx          | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/dlc_developer_config.toml b/dlc_developer_config.toml
index 1f6a589ccc14..f250d72804a2 100644
--- a/dlc_developer_config.toml
+++ b/dlc_developer_config.toml
@@ -9,7 +9,7 @@ ei_mode = false
 neuron_mode = false
 # Please only set it to true if you are preparing a NEURONX related PR
 # Do remember to revert it back to false before merging any PR (including NEURONX dedicated PR)
-neuronx_mode = false
+neuronx_mode = true
 # Please only set it to true if you are preparing a GRAVITON related PR
 # Do remember to revert it back to false before merging any PR (including GRAVITON dedicated PR)
 graviton_mode = false
@@ -34,10 +34,10 @@ deep_canary_mode = false
 [build]
 # Add in frameworks you would like to build. By default, builds are disabled unless you specify building an image.
 # available frameworks - ["autogluon", "huggingface_tensorflow", "huggingface_pytorch", "huggingface_tensorflow_trcomp", "huggingface_pytorch_trcomp", "pytorch_trcomp", "tensorflow", "mxnet", "pytorch", "stabilityai_pytorch"]
-build_frameworks = []
+build_frameworks = ["huggingface_pytorch"]
 
 # By default we build both training and inference containers. Set true/false values to determine which to build.
-build_training = true
+build_training = false
 build_inference = true
 
 # Set do_build to "false" to skip builds and test the latest image built by this PR
@@ -143,7 +143,7 @@ dlc-pr-tensorflow-2-neuron-inference = ""
 # HuggingFace Inference
 dlc-pr-huggingface-tensorflow-inference = ""
 dlc-pr-huggingface-pytorch-inference = ""
-dlc-pr-huggingface-pytorch-neuron-inference = ""
+dlc-pr-huggingface-pytorch-neuron-inference = "huggingface/pytorch/inference/buildspec-1-13-1-neuronx.yml"
 
 # Stability AI Inference
 dlc-pr-stabilityai-pytorch-inference = ""
diff --git a/huggingface/pytorch/inference/docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx b/huggingface/pytorch/inference/docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx
index 51cbf4ee87b9..1def834fec86 100644
--- a/huggingface/pytorch/inference/docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx
+++ b/huggingface/pytorch/inference/docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx
@@ -62,9 +62,9 @@ RUN apt-get update \
     zlib1g-dev \
     libcap-dev \
     gpg-agent \
+    libarchive13 \
     expat \
     libexpat1 \
-    libarchive13 \
  && rm -rf /var/lib/apt/lists/* \
  && rm -rf /tmp/tmp* \
  && apt-get clean

From 66f46e474ed57abe8272c6e9b2d4da14a3c2813e Mon Sep 17 00:00:00 2001
From: malavhs <malavhs@amazon.com>
Date: Tue, 22 Oct 2024 03:46:37 +0000
Subject: [PATCH 4/4] fix integ tests

---
 dlc_developer_config.toml                                 | 8 ++++----
 .../docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx          | 2 ++
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/dlc_developer_config.toml b/dlc_developer_config.toml
index f250d72804a2..1f6a589ccc14 100644
--- a/dlc_developer_config.toml
+++ b/dlc_developer_config.toml
@@ -9,7 +9,7 @@ ei_mode = false
 neuron_mode = false
 # Please only set it to true if you are preparing a NEURONX related PR
 # Do remember to revert it back to false before merging any PR (including NEURONX dedicated PR)
-neuronx_mode = true
+neuronx_mode = false
 # Please only set it to true if you are preparing a GRAVITON related PR
 # Do remember to revert it back to false before merging any PR (including GRAVITON dedicated PR)
 graviton_mode = false
@@ -34,10 +34,10 @@ deep_canary_mode = false
 [build]
 # Add in frameworks you would like to build. By default, builds are disabled unless you specify building an image.
 # available frameworks - ["autogluon", "huggingface_tensorflow", "huggingface_pytorch", "huggingface_tensorflow_trcomp", "huggingface_pytorch_trcomp", "pytorch_trcomp", "tensorflow", "mxnet", "pytorch", "stabilityai_pytorch"]
-build_frameworks = ["huggingface_pytorch"]
+build_frameworks = []
 
 # By default we build both training and inference containers. Set true/false values to determine which to build.
-build_training = false
+build_training = true
 build_inference = true
 
 # Set do_build to "false" to skip builds and test the latest image built by this PR
@@ -143,7 +143,7 @@ dlc-pr-tensorflow-2-neuron-inference = ""
 # HuggingFace Inference
 dlc-pr-huggingface-tensorflow-inference = ""
 dlc-pr-huggingface-pytorch-inference = ""
-dlc-pr-huggingface-pytorch-neuron-inference = "huggingface/pytorch/inference/buildspec-1-13-1-neuronx.yml"
+dlc-pr-huggingface-pytorch-neuron-inference = ""
 
 # Stability AI Inference
 dlc-pr-stabilityai-pytorch-inference = ""
diff --git a/huggingface/pytorch/inference/docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx b/huggingface/pytorch/inference/docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx
index 1def834fec86..6ce00e81c3cf 100644
--- a/huggingface/pytorch/inference/docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx
+++ b/huggingface/pytorch/inference/docker/1.13/py3/sdk2.16.1/Dockerfile.neuronx
@@ -24,6 +24,7 @@ ARG TRANSFORMERS_VERSION
 ARG DIFFUSERS_VERSION=0.25.1
 ARG OPTIMUM_NEURON_VERSION=0.0.18
 ARG SENTENCE_TRANSFORMERS=2.2.2
+ARG HUGGINGFACE_HUB_VERSION=0.25.2
 
 # See http://bugs.python.org/issue19846
 ENV LANG C.UTF-8
@@ -176,6 +177,7 @@ RUN pip install --no-cache-dir \
 	transformers[sentencepiece,audio,vision]==${TRANSFORMERS_VERSION} \
     diffusers==${DIFFUSERS_VERSION} \
     optimum-neuron==${OPTIMUM_NEURON_VERSION} \
+    huggingface_hub==${HUGGINGFACE_HUB_VERSION} \
     sentence_transformers==${SENTENCE_TRANSFORMERS} \
 	"sagemaker-huggingface-inference-toolkit<3"