We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Better model security with new PyTorch version
When loading PyTorch models from the modelhub, arbitrary code can be executed. See [here.](https://huggingface.co/docs/hub/security-pickle#pickle-scanning)

Seems like PyTorch already solved this:
- Issue on the PyTorch Repo: https://github.com/pytorch/pytorch/issues/52596
- By default, this is not available in torch==1.13. TORCH_FORCE_WEIGHTS_ONLY_LOAD needs to be set to True which allows global override to safe only model loading via.

Test
Test haystack tests with new flags

**Solution:**
- Bump up PyTorch version to 1.13

**Behaviour**
- Secure by default TORCH_FORCE_WEIGHTS_ONLY_LOAD always set to true when Haystack loads any models



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `haystack/__init__.py`
Content:
```
1 # pylint: disable=wrong-import-position,wrong-import-order
2 
3 from typing import Union
4 from types import ModuleType
5 
6 try:
7     from importlib import metadata
8 except (ModuleNotFoundError, ImportError):
9     # Python <= 3.7
10     import importlib_metadata as metadata  # type: ignore
11 
12 __version__: str = str(metadata.version("farm-haystack"))
13 
14 
15 # Logging is not configured here on purpose, see https://github.com/deepset-ai/haystack/issues/2485
16 import logging
17 
18 import pandas as pd
19 
20 from haystack.schema import Document, Answer, Label, MultiLabel, Span, EvaluationResult
21 from haystack.nodes.base import BaseComponent
22 from haystack.pipelines.base import Pipeline
23 
24 
25 pd.options.display.max_colwidth = 80
26
```

Path: `haystack/environment.py`
Content:
```
1 import os
2 import platform
3 import sys
4 from typing import Any, Dict
5 import torch
6 import transformers
7 
8 from haystack import __version__
9 
10 
11 HAYSTACK_EXECUTION_CONTEXT = "HAYSTACK_EXECUTION_CONTEXT"
12 HAYSTACK_DOCKER_CONTAINER = "HAYSTACK_DOCKER_CONTAINER"
13 
14 # Any remote API (OpenAI, Cohere etc.)
15 HAYSTACK_REMOTE_API_BACKOFF_SEC = "HAYSTACK_REMOTE_API_BACKOFF_SEC"
16 HAYSTACK_REMOTE_API_MAX_RETRIES = "HAYSTACK_REMOTE_API_MAX_RETRIES"
17 
18 env_meta_data: Dict[str, Any] = {}
19 
20 
21 def get_or_create_env_meta_data() -> Dict[str, Any]:
22     """
23     Collects meta data about the setup that is used with Haystack, such as: operating system, python version, Haystack version, transformers version, pytorch version, number of GPUs, execution environment, and the value stored in the env variable HAYSTACK_EXECUTION_CONTEXT.
24     """
25     global env_meta_data  # pylint: disable=global-statement
26     if not env_meta_data:
27         env_meta_data = {
28             "os_version": platform.release(),
29             "os_family": platform.system(),
30             "os_machine": platform.machine(),
31             "python_version": platform.python_version(),
32             "haystack_version": __version__,
33             "transformers_version": transformers.__version__,
34             "torch_version": torch.__version__,
35             "torch_cuda_version": torch.version.cuda if torch.cuda.is_available() else 0,
36             "n_gpu": torch.cuda.device_count() if torch.cuda.is_available() else 0,
37             "n_cpu": os.cpu_count(),
38             "context": os.environ.get(HAYSTACK_EXECUTION_CONTEXT),
39             "execution_env": _get_execution_environment(),
40         }
41     return env_meta_data
42 
43 
44 def _get_execution_environment():
45     """
46     Identifies the execution environment that Haystack is running in.
47     Options are: colab notebook, kubernetes, CPU/GPU docker container, test environment, jupyter notebook, python script
48     """
49     if os.environ.get("CI", "False").lower() == "true":
50         execution_env = "ci"
51     elif "google.colab" in sys.modules:
52         execution_env = "colab"
53     elif "KUBERNETES_SERVICE_HOST" in os.environ:
54         execution_env = "kubernetes"
55     elif HAYSTACK_DOCKER_CONTAINER in os.environ:
56         execution_env = os.environ.get(HAYSTACK_DOCKER_CONTAINER)
57     # check if pytest is imported
58     elif "pytest" in sys.modules:
59         execution_env = "test"
60     else:
61         try:
62             execution_env = get_ipython().__class__.__name__  # pylint: disable=undefined-variable
63         except NameError:
64             execution_env = "script"
65     return execution_env
66
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/haystack/__init__.py b/haystack/__init__.py
--- a/haystack/__init__.py
+++ b/haystack/__init__.py
@@ -20,6 +20,8 @@
 from haystack.schema import Document, Answer, Label, MultiLabel, Span, EvaluationResult
 from haystack.nodes.base import BaseComponent
 from haystack.pipelines.base import Pipeline
+from haystack.environment import set_pytorch_secure_model_loading
 
 
 pd.options.display.max_colwidth = 80
+set_pytorch_secure_model_loading()
diff --git a/haystack/environment.py b/haystack/environment.py
--- a/haystack/environment.py
+++ b/haystack/environment.py
@@ -1,3 +1,4 @@
+import logging
 import os
 import platform
 import sys
@@ -17,6 +18,18 @@
 
 env_meta_data: Dict[str, Any] = {}
 
+logger = logging.getLogger(__name__)
+
+
+def set_pytorch_secure_model_loading(flag_val="1"):
+    # To load secure only model pytorch requires value of
+    # TORCH_FORCE_WEIGHTS_ONLY_LOAD to be ["1", "y", "yes", "true"]
+    os_flag_val = os.getenv("TORCH_FORCE_WEIGHTS_ONLY_LOAD")
+    if os_flag_val is None:
+        os.environ["TORCH_FORCE_WEIGHTS_ONLY_LOAD"] = flag_val
+    else:
+        logger.info("TORCH_FORCE_WEIGHTS_ONLY_LOAD is already set to %s, Haystack will use the same.", os_flag_val)
+
 
 def get_or_create_env_meta_data() -> Dict[str, Any]:
     """

{"golden_diff": "diff --git a/haystack/__init__.py b/haystack/__init__.py\n--- a/haystack/__init__.py\n+++ b/haystack/__init__.py\n@@ -20,6 +20,8 @@\n from haystack.schema import Document, Answer, Label, MultiLabel, Span, EvaluationResult\n from haystack.nodes.base import BaseComponent\n from haystack.pipelines.base import Pipeline\n+from haystack.environment import set_pytorch_secure_model_loading\n \n \n pd.options.display.max_colwidth = 80\n+set_pytorch_secure_model_loading()\ndiff --git a/haystack/environment.py b/haystack/environment.py\n--- a/haystack/environment.py\n+++ b/haystack/environment.py\n@@ -1,3 +1,4 @@\n+import logging\n import os\n import platform\n import sys\n@@ -17,6 +18,18 @@\n \n env_meta_data: Dict[str, Any] = {}\n \n+logger = logging.getLogger(__name__)\n+\n+\n+def set_pytorch_secure_model_loading(flag_val=\"1\"):\n+    # To load secure only model pytorch requires value of\n+    # TORCH_FORCE_WEIGHTS_ONLY_LOAD to be [\"1\", \"y\", \"yes\", \"true\"]\n+    os_flag_val = os.getenv(\"TORCH_FORCE_WEIGHTS_ONLY_LOAD\")\n+    if os_flag_val is None:\n+        os.environ[\"TORCH_FORCE_WEIGHTS_ONLY_LOAD\"] = flag_val\n+    else:\n+        logger.info(\"TORCH_FORCE_WEIGHTS_ONLY_LOAD is already set to %s, Haystack will use the same.\", os_flag_val)\n+\n \n def get_or_create_env_meta_data() -> Dict[str, Any]:\n     \"\"\"\n", "issue": "Better model security with new PyTorch version\nWhen loading PyTorch models from the modelhub, arbitrary code can be executed. See [here.](https://huggingface.co/docs/hub/security-pickle#pickle-scanning)\r\n\r\nSeems like PyTorch already solved this:\r\n- Issue on the PyTorch Repo: https://github.com/pytorch/pytorch/issues/52596\r\n- By default, this is not available in torch==1.13. TORCH_FORCE_WEIGHTS_ONLY_LOAD needs to be set to True which allows global override to safe only model loading via.\r\n\r\nTest\r\nTest haystack tests with new flags\r\n\r\n**Solution:**\r\n- Bump up PyTorch version to 1.13\r\n\r\n**Behaviour**\r\n- Secure by default TORCH_FORCE_WEIGHTS_ONLY_LOAD always set to true when Haystack loads any models\r\n\r\n\n", "before_files": [{"content": "# pylint: disable=wrong-import-position,wrong-import-order\n\nfrom typing import Union\nfrom types import ModuleType\n\ntry:\n    from importlib import metadata\nexcept (ModuleNotFoundError, ImportError):\n    # Python <= 3.7\n    import importlib_metadata as metadata  # type: ignore\n\n__version__: str = str(metadata.version(\"farm-haystack\"))\n\n\n# Logging is not configured here on purpose, see https://github.com/deepset-ai/haystack/issues/2485\nimport logging\n\nimport pandas as pd\n\nfrom haystack.schema import Document, Answer, Label, MultiLabel, Span, EvaluationResult\nfrom haystack.nodes.base import BaseComponent\nfrom haystack.pipelines.base import Pipeline\n\n\npd.options.display.max_colwidth = 80\n", "path": "haystack/__init__.py"}, {"content": "import os\nimport platform\nimport sys\nfrom typing import Any, Dict\nimport torch\nimport transformers\n\nfrom haystack import __version__\n\n\nHAYSTACK_EXECUTION_CONTEXT = \"HAYSTACK_EXECUTION_CONTEXT\"\nHAYSTACK_DOCKER_CONTAINER = \"HAYSTACK_DOCKER_CONTAINER\"\n\n# Any remote API (OpenAI, Cohere etc.)\nHAYSTACK_REMOTE_API_BACKOFF_SEC = \"HAYSTACK_REMOTE_API_BACKOFF_SEC\"\nHAYSTACK_REMOTE_API_MAX_RETRIES = \"HAYSTACK_REMOTE_API_MAX_RETRIES\"\n\nenv_meta_data: Dict[str, Any] = {}\n\n\ndef get_or_create_env_meta_data() -> Dict[str, Any]:\n    \"\"\"\n    Collects meta data about the setup that is used with Haystack, such as: operating system, python version, Haystack version, transformers version, pytorch version, number of GPUs, execution environment, and the value stored in the env variable HAYSTACK_EXECUTION_CONTEXT.\n    \"\"\"\n    global env_meta_data  # pylint: disable=global-statement\n    if not env_meta_data:\n        env_meta_data = {\n            \"os_version\": platform.release(),\n            \"os_family\": platform.system(),\n            \"os_machine\": platform.machine(),\n            \"python_version\": platform.python_version(),\n            \"haystack_version\": __version__,\n            \"transformers_version\": transformers.__version__,\n            \"torch_version\": torch.__version__,\n            \"torch_cuda_version\": torch.version.cuda if torch.cuda.is_available() else 0,\n            \"n_gpu\": torch.cuda.device_count() if torch.cuda.is_available() else 0,\n            \"n_cpu\": os.cpu_count(),\n            \"context\": os.environ.get(HAYSTACK_EXECUTION_CONTEXT),\n            \"execution_env\": _get_execution_environment(),\n        }\n    return env_meta_data\n\n\ndef _get_execution_environment():\n    \"\"\"\n    Identifies the execution environment that Haystack is running in.\n    Options are: colab notebook, kubernetes, CPU/GPU docker container, test environment, jupyter notebook, python script\n    \"\"\"\n    if os.environ.get(\"CI\", \"False\").lower() == \"true\":\n        execution_env = \"ci\"\n    elif \"google.colab\" in sys.modules:\n        execution_env = \"colab\"\n    elif \"KUBERNETES_SERVICE_HOST\" in os.environ:\n        execution_env = \"kubernetes\"\n    elif HAYSTACK_DOCKER_CONTAINER in os.environ:\n        execution_env = os.environ.get(HAYSTACK_DOCKER_CONTAINER)\n    # check if pytest is imported\n    elif \"pytest\" in sys.modules:\n        execution_env = \"test\"\n    else:\n        try:\n            execution_env = get_ipython().__class__.__name__  # pylint: disable=undefined-variable\n        except NameError:\n            execution_env = \"script\"\n    return execution_env\n", "path": "haystack/environment.py"}], "after_files": [{"content": "# pylint: disable=wrong-import-position,wrong-import-order\n\nfrom typing import Union\nfrom types import ModuleType\n\ntry:\n    from importlib import metadata\nexcept (ModuleNotFoundError, ImportError):\n    # Python <= 3.7\n    import importlib_metadata as metadata  # type: ignore\n\n__version__: str = str(metadata.version(\"farm-haystack\"))\n\n\n# Logging is not configured here on purpose, see https://github.com/deepset-ai/haystack/issues/2485\nimport logging\n\nimport pandas as pd\n\nfrom haystack.schema import Document, Answer, Label, MultiLabel, Span, EvaluationResult\nfrom haystack.nodes.base import BaseComponent\nfrom haystack.pipelines.base import Pipeline\nfrom haystack.environment import set_pytorch_secure_model_loading\n\n\npd.options.display.max_colwidth = 80\nset_pytorch_secure_model_loading()\n", "path": "haystack/__init__.py"}, {"content": "import logging\nimport os\nimport platform\nimport sys\nfrom typing import Any, Dict\nimport torch\nimport transformers\n\nfrom haystack import __version__\n\n\nHAYSTACK_EXECUTION_CONTEXT = \"HAYSTACK_EXECUTION_CONTEXT\"\nHAYSTACK_DOCKER_CONTAINER = \"HAYSTACK_DOCKER_CONTAINER\"\n\n# Any remote API (OpenAI, Cohere etc.)\nHAYSTACK_REMOTE_API_BACKOFF_SEC = \"HAYSTACK_REMOTE_API_BACKOFF_SEC\"\nHAYSTACK_REMOTE_API_MAX_RETRIES = \"HAYSTACK_REMOTE_API_MAX_RETRIES\"\n\nenv_meta_data: Dict[str, Any] = {}\n\nlogger = logging.getLogger(__name__)\n\n\ndef set_pytorch_secure_model_loading(flag_val=\"1\"):\n    # To load secure only model pytorch requires value of\n    # TORCH_FORCE_WEIGHTS_ONLY_LOAD to be [\"1\", \"y\", \"yes\", \"true\"]\n    os_flag_val = os.getenv(\"TORCH_FORCE_WEIGHTS_ONLY_LOAD\")\n    if os_flag_val is None:\n        os.environ[\"TORCH_FORCE_WEIGHTS_ONLY_LOAD\"] = flag_val\n    else:\n        logger.info(\"TORCH_FORCE_WEIGHTS_ONLY_LOAD is already set to %s, Haystack will use the same.\", os_flag_val)\n\n\ndef get_or_create_env_meta_data() -> Dict[str, Any]:\n    \"\"\"\n    Collects meta data about the setup that is used with Haystack, such as: operating system, python version, Haystack version, transformers version, pytorch version, number of GPUs, execution environment, and the value stored in the env variable HAYSTACK_EXECUTION_CONTEXT.\n    \"\"\"\n    global env_meta_data  # pylint: disable=global-statement\n    if not env_meta_data:\n        env_meta_data = {\n            \"os_version\": platform.release(),\n            \"os_family\": platform.system(),\n            \"os_machine\": platform.machine(),\n            \"python_version\": platform.python_version(),\n            \"haystack_version\": __version__,\n            \"transformers_version\": transformers.__version__,\n            \"torch_version\": torch.__version__,\n            \"torch_cuda_version\": torch.version.cuda if torch.cuda.is_available() else 0,\n            \"n_gpu\": torch.cuda.device_count() if torch.cuda.is_available() else 0,\n            \"n_cpu\": os.cpu_count(),\n            \"context\": os.environ.get(HAYSTACK_EXECUTION_CONTEXT),\n            \"execution_env\": _get_execution_environment(),\n        }\n    return env_meta_data\n\n\ndef _get_execution_environment():\n    \"\"\"\n    Identifies the execution environment that Haystack is running in.\n    Options are: colab notebook, kubernetes, CPU/GPU docker container, test environment, jupyter notebook, python script\n    \"\"\"\n    if os.environ.get(\"CI\", \"False\").lower() == \"true\":\n        execution_env = \"ci\"\n    elif \"google.colab\" in sys.modules:\n        execution_env = \"colab\"\n    elif \"KUBERNETES_SERVICE_HOST\" in os.environ:\n        execution_env = \"kubernetes\"\n    elif HAYSTACK_DOCKER_CONTAINER in os.environ:\n        execution_env = os.environ.get(HAYSTACK_DOCKER_CONTAINER)\n    # check if pytest is imported\n    elif \"pytest\" in sys.modules:\n        execution_env = \"test\"\n    else:\n        try:\n            execution_env = get_ipython().__class__.__name__  # pylint: disable=undefined-variable\n        except NameError:\n            execution_env = \"script\"\n    return execution_env\n", "path": "haystack/environment.py"}]}