{ "cells": [ { "cell_type": "code", "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2025-07-04T21:11:11.583344Z", "start_time": "2025-07-04T21:11:11.578562Z" } }, "source": [ "import time\n", "import gc" ], "outputs": [], "execution_count": 1 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:11:17.027661Z", "start_time": "2025-07-04T21:11:12.525141Z" } }, "cell_type": "code", "source": [ "import torch\n", "from transformers import pipeline, AutoTokenizer" ], "id": "e903986d60118c74", "outputs": [], "execution_count": 2 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-29T17:17:57.370702Z", "start_time": "2025-06-29T17:17:55.802730Z" } }, "cell_type": "code", "source": [ "model_id = \"Qwen/Qwen3-0.6B\"\n", "tokenizer = AutoTokenizer.from_pretrained(model_id)" ], "id": "bf069971fdf008ac", "outputs": [], "execution_count": 3 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:02:40.158670Z", "start_time": "2025-07-04T21:02:38.159946Z" } }, "cell_type": "code", "source": [ "model_id = \"meta-llama/Llama-3.2-1B-Instruct\"\n", "tokenizer = AutoTokenizer.from_pretrained(model_id)" ], "id": "88237ed2d6f9f3ad", "outputs": [], "execution_count": 3 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:21:27.591038Z", "start_time": "2025-07-04T21:11:23.488011Z" } }, "cell_type": "code", "source": "pipe = pipeline(\"text-generation\", model=\"meta-llama/Llama-3.2-3B-Instruct\")", "id": "6bc20dc4a9d4d087", "outputs": [ { "data": { "text/plain": [ "config.json: 0%| | 0.00/878 [00:00, ). See the original errors:\n\nwhile loading with AutoModelForCausalLM, an error is thrown:\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 198, in _new_conn\n sock = connection.create_connection(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/util/connection.py\", line 60, in create_connection\n for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):\n File \"/usr/lib/python3.10/socket.py\", line 955, in getaddrinfo\n for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\nsocket.gaierror: [Errno -2] Name or service not known\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 787, in urlopen\n response = self._make_request(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 488, in _make_request\n raise new_e\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 464, in _make_request\n self._validate_conn(conn)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 1093, in _validate_conn\n conn.connect()\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 753, in connect\n self.sock = sock = self._new_conn()\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 205, in _new_conn\n raise NameResolutionError(self.host, self, e) from e\nurllib3.exceptions.NameResolutionError: : Failed to resolve 'huggingface.co' ([Errno -2] Name or service not known)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/adapters.py\", line 667, in send\n resp = conn.urlopen(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 841, in urlopen\n retries = retries.increment(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/util/retry.py\", line 519, in increment\n raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]\nurllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /meta-llama/Llama-3.2-3B-Instruct/resolve/0cb88a4f764b7a12671c53f0838cd831a0843b95/model-00001-of-00002.safetensors (Caused by NameResolutionError(\": Failed to resolve 'huggingface.co' ([Errno -2] Name or service not known)\"))\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1533, in _get_metadata_or_catch_error\n metadata = get_hf_file_metadata(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1450, in get_hf_file_metadata\n r = _request_wrapper(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 286, in _request_wrapper\n response = _request_wrapper(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 309, in _request_wrapper\n response = http_backoff(method=method, url=url, **params, retry_on_exceptions=(), retry_on_status_codes=(429,))\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_http.py\", line 310, in http_backoff\n response = session.request(method=method, url=url, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/sessions.py\", line 589, in request\n resp = self.send(prep, **send_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/sessions.py\", line 703, in send\n r = adapter.send(request, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_http.py\", line 96, in send\n return super().send(request, *args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/adapters.py\", line 700, in send\n raise ConnectionError(e, request=request)\nrequests.exceptions.ConnectionError: (MaxRetryError('HTTPSConnectionPool(host=\\'huggingface.co\\', port=443): Max retries exceeded with url: /meta-llama/Llama-3.2-3B-Instruct/resolve/0cb88a4f764b7a12671c53f0838cd831a0843b95/model-00001-of-00002.safetensors (Caused by NameResolutionError(\": Failed to resolve \\'huggingface.co\\' ([Errno -2] Name or service not known)\"))'), '(Request ID: 73f62aa8-400e-438e-ba10-db8782b0c884)')\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 485, in cached_files\n snapshot_download(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py\", line 327, in snapshot_download\n thread_map(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/contrib/concurrent.py\", line 69, in thread_map\n return _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/contrib/concurrent.py\", line 51, in _executor_map\n return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs))\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/notebook.py\", line 250, in __iter__\n for obj in it:\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/std.py\", line 1181, in __iter__\n for obj in iterable:\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 621, in result_iterator\n yield _result_or_cancel(fs.pop())\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 319, in _result_or_cancel\n return fut.result(timeout)\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 458, in result\n return self.__get_result()\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 403, in __get_result\n raise self._exception\n File \"/usr/lib/python3.10/concurrent/futures/thread.py\", line 58, in run\n result = self.fn(*self.args, **self.kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py\", line 301, in _inner_hf_hub_download\n return hf_hub_download(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1008, in hf_hub_download\n return _hf_hub_download_to_cache_dir(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1115, in _hf_hub_download_to_cache_dir\n _raise_on_head_call_error(head_call_error, force_download, local_files_only)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1648, in _raise_on_head_call_error\n raise LocalEntryNotFoundError(\nhuggingface_hub.errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/base.py\", line 310, in infer_framework_load_model\n model = model_class.from_pretrained(model, **fp32_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py\", line 600, in from_pretrained\n return model_class.from_pretrained(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 311, in _wrapper\n return func(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 4674, in from_pretrained\n checkpoint_files, sharded_metadata = _get_resolved_checkpoint_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 1295, in _get_resolved_checkpoint_files\n checkpoint_files, sharded_metadata = get_checkpoint_shard_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 1110, in get_checkpoint_shard_files\n cached_filenames = cached_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 543, in cached_files\n raise OSError(\nOSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.\nCheck your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.\n\nwhile loading with LlamaForCausalLM, an error is thrown:\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 198, in _new_conn\n sock = connection.create_connection(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/util/connection.py\", line 60, in create_connection\n for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):\n File \"/usr/lib/python3.10/socket.py\", line 955, in getaddrinfo\n for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\nsocket.gaierror: [Errno -2] Name or service not known\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 787, in urlopen\n response = self._make_request(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 488, in _make_request\n raise new_e\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 464, in _make_request\n self._validate_conn(conn)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 1093, in _validate_conn\n conn.connect()\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 753, in connect\n self.sock = sock = self._new_conn()\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 205, in _new_conn\n raise NameResolutionError(self.host, self, e) from e\nurllib3.exceptions.NameResolutionError: : Failed to resolve 'huggingface.co' ([Errno -2] Name or service not known)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/adapters.py\", line 667, in send\n resp = conn.urlopen(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 841, in urlopen\n retries = retries.increment(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/util/retry.py\", line 519, in increment\n raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]\nurllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /meta-llama/Llama-3.2-3B-Instruct/resolve/0cb88a4f764b7a12671c53f0838cd831a0843b95/model-00001-of-00002.safetensors (Caused by NameResolutionError(\": Failed to resolve 'huggingface.co' ([Errno -2] Name or service not known)\"))\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1533, in _get_metadata_or_catch_error\n metadata = get_hf_file_metadata(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1450, in get_hf_file_metadata\n r = _request_wrapper(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 286, in _request_wrapper\n response = _request_wrapper(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 309, in _request_wrapper\n response = http_backoff(method=method, url=url, **params, retry_on_exceptions=(), retry_on_status_codes=(429,))\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_http.py\", line 310, in http_backoff\n response = session.request(method=method, url=url, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/sessions.py\", line 589, in request\n resp = self.send(prep, **send_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/sessions.py\", line 703, in send\n r = adapter.send(request, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_http.py\", line 96, in send\n return super().send(request, *args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/adapters.py\", line 700, in send\n raise ConnectionError(e, request=request)\nrequests.exceptions.ConnectionError: (MaxRetryError('HTTPSConnectionPool(host=\\'huggingface.co\\', port=443): Max retries exceeded with url: /meta-llama/Llama-3.2-3B-Instruct/resolve/0cb88a4f764b7a12671c53f0838cd831a0843b95/model-00001-of-00002.safetensors (Caused by NameResolutionError(\": Failed to resolve \\'huggingface.co\\' ([Errno -2] Name or service not known)\"))'), '(Request ID: a2c1fe16-aa95-47bd-91b8-930687f1762d)')\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 485, in cached_files\n snapshot_download(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py\", line 327, in snapshot_download\n thread_map(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/contrib/concurrent.py\", line 69, in thread_map\n return _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/contrib/concurrent.py\", line 51, in _executor_map\n return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs))\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/notebook.py\", line 250, in __iter__\n for obj in it:\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/std.py\", line 1181, in __iter__\n for obj in iterable:\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 621, in result_iterator\n yield _result_or_cancel(fs.pop())\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 319, in _result_or_cancel\n return fut.result(timeout)\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 458, in result\n return self.__get_result()\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 403, in __get_result\n raise self._exception\n File \"/usr/lib/python3.10/concurrent/futures/thread.py\", line 58, in run\n result = self.fn(*self.args, **self.kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py\", line 301, in _inner_hf_hub_download\n return hf_hub_download(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1008, in hf_hub_download\n return _hf_hub_download_to_cache_dir(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1115, in _hf_hub_download_to_cache_dir\n _raise_on_head_call_error(head_call_error, force_download, local_files_only)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1648, in _raise_on_head_call_error\n raise LocalEntryNotFoundError(\nhuggingface_hub.errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/base.py\", line 310, in infer_framework_load_model\n model = model_class.from_pretrained(model, **fp32_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 311, in _wrapper\n return func(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 4674, in from_pretrained\n checkpoint_files, sharded_metadata = _get_resolved_checkpoint_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 1295, in _get_resolved_checkpoint_files\n checkpoint_files, sharded_metadata = get_checkpoint_shard_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 1110, in get_checkpoint_shard_files\n cached_filenames = cached_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 543, in cached_files\n raise OSError(\nOSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.\nCheck your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.\n\n\n", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mValueError\u001B[0m Traceback (most recent call last)", "Cell \u001B[0;32mIn[3], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m pipe \u001B[38;5;241m=\u001B[39m \u001B[43mpipeline\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mtext-generation\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmodel\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mmeta-llama/Llama-3.2-3B-Instruct\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\n", "File \u001B[0;32m~/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/__init__.py:1030\u001B[0m, in \u001B[0;36mpipeline\u001B[0;34m(task, model, config, tokenizer, feature_extractor, image_processor, processor, framework, revision, use_fast, token, device, device_map, torch_dtype, trust_remote_code, model_kwargs, pipeline_class, **kwargs)\u001B[0m\n\u001B[1;32m 1028\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(model, \u001B[38;5;28mstr\u001B[39m) \u001B[38;5;129;01mor\u001B[39;00m framework \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[1;32m 1029\u001B[0m model_classes \u001B[38;5;241m=\u001B[39m {\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtf\u001B[39m\u001B[38;5;124m\"\u001B[39m: targeted_task[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtf\u001B[39m\u001B[38;5;124m\"\u001B[39m], \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mpt\u001B[39m\u001B[38;5;124m\"\u001B[39m: targeted_task[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mpt\u001B[39m\u001B[38;5;124m\"\u001B[39m]}\n\u001B[0;32m-> 1030\u001B[0m framework, model \u001B[38;5;241m=\u001B[39m \u001B[43minfer_framework_load_model\u001B[49m\u001B[43m(\u001B[49m\n\u001B[1;32m 1031\u001B[0m \u001B[43m \u001B[49m\u001B[43madapter_path\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;28;43;01mif\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43madapter_path\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01mis\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[38;5;129;43;01mnot\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[38;5;28;43;01mNone\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[38;5;28;43;01melse\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mmodel\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 1032\u001B[0m \u001B[43m \u001B[49m\u001B[43mmodel_classes\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mmodel_classes\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 1033\u001B[0m \u001B[43m \u001B[49m\u001B[43mconfig\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mconfig\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 1034\u001B[0m \u001B[43m \u001B[49m\u001B[43mframework\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mframework\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 1035\u001B[0m \u001B[43m \u001B[49m\u001B[43mtask\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mtask\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 1036\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mhub_kwargs\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 1037\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mmodel_kwargs\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 1038\u001B[0m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 1040\u001B[0m model_config \u001B[38;5;241m=\u001B[39m model\u001B[38;5;241m.\u001B[39mconfig\n\u001B[1;32m 1041\u001B[0m hub_kwargs[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m model\u001B[38;5;241m.\u001B[39mconfig\u001B[38;5;241m.\u001B[39m_commit_hash\n", "File \u001B[0;32m~/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/base.py:332\u001B[0m, in \u001B[0;36minfer_framework_load_model\u001B[0;34m(model, config, model_classes, task, framework, **model_kwargs)\u001B[0m\n\u001B[1;32m 330\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m class_name, trace \u001B[38;5;129;01min\u001B[39;00m all_traceback\u001B[38;5;241m.\u001B[39mitems():\n\u001B[1;32m 331\u001B[0m error \u001B[38;5;241m+\u001B[39m\u001B[38;5;241m=\u001B[39m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mwhile loading with \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mclass_name\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m, an error is thrown:\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;132;01m{\u001B[39;00mtrace\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m--> 332\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[1;32m 333\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mCould not load model \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mmodel\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m with any of the following classes: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mclass_tuple\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m. See the original errors:\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;132;01m{\u001B[39;00merror\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 334\u001B[0m )\n\u001B[1;32m 336\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m framework \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[1;32m 337\u001B[0m framework \u001B[38;5;241m=\u001B[39m infer_framework(model\u001B[38;5;241m.\u001B[39m\u001B[38;5;18m__class__\u001B[39m)\n", "\u001B[0;31mValueError\u001B[0m: Could not load model meta-llama/Llama-3.2-3B-Instruct with any of the following classes: (, ). See the original errors:\n\nwhile loading with AutoModelForCausalLM, an error is thrown:\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 198, in _new_conn\n sock = connection.create_connection(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/util/connection.py\", line 60, in create_connection\n for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):\n File \"/usr/lib/python3.10/socket.py\", line 955, in getaddrinfo\n for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\nsocket.gaierror: [Errno -2] Name or service not known\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 787, in urlopen\n response = self._make_request(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 488, in _make_request\n raise new_e\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 464, in _make_request\n self._validate_conn(conn)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 1093, in _validate_conn\n conn.connect()\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 753, in connect\n self.sock = sock = self._new_conn()\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 205, in _new_conn\n raise NameResolutionError(self.host, self, e) from e\nurllib3.exceptions.NameResolutionError: : Failed to resolve 'huggingface.co' ([Errno -2] Name or service not known)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/adapters.py\", line 667, in send\n resp = conn.urlopen(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 841, in urlopen\n retries = retries.increment(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/util/retry.py\", line 519, in increment\n raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]\nurllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /meta-llama/Llama-3.2-3B-Instruct/resolve/0cb88a4f764b7a12671c53f0838cd831a0843b95/model-00001-of-00002.safetensors (Caused by NameResolutionError(\": Failed to resolve 'huggingface.co' ([Errno -2] Name or service not known)\"))\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1533, in _get_metadata_or_catch_error\n metadata = get_hf_file_metadata(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1450, in get_hf_file_metadata\n r = _request_wrapper(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 286, in _request_wrapper\n response = _request_wrapper(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 309, in _request_wrapper\n response = http_backoff(method=method, url=url, **params, retry_on_exceptions=(), retry_on_status_codes=(429,))\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_http.py\", line 310, in http_backoff\n response = session.request(method=method, url=url, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/sessions.py\", line 589, in request\n resp = self.send(prep, **send_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/sessions.py\", line 703, in send\n r = adapter.send(request, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_http.py\", line 96, in send\n return super().send(request, *args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/adapters.py\", line 700, in send\n raise ConnectionError(e, request=request)\nrequests.exceptions.ConnectionError: (MaxRetryError('HTTPSConnectionPool(host=\\'huggingface.co\\', port=443): Max retries exceeded with url: /meta-llama/Llama-3.2-3B-Instruct/resolve/0cb88a4f764b7a12671c53f0838cd831a0843b95/model-00001-of-00002.safetensors (Caused by NameResolutionError(\": Failed to resolve \\'huggingface.co\\' ([Errno -2] Name or service not known)\"))'), '(Request ID: 73f62aa8-400e-438e-ba10-db8782b0c884)')\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 485, in cached_files\n snapshot_download(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py\", line 327, in snapshot_download\n thread_map(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/contrib/concurrent.py\", line 69, in thread_map\n return _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/contrib/concurrent.py\", line 51, in _executor_map\n return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs))\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/notebook.py\", line 250, in __iter__\n for obj in it:\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/std.py\", line 1181, in __iter__\n for obj in iterable:\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 621, in result_iterator\n yield _result_or_cancel(fs.pop())\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 319, in _result_or_cancel\n return fut.result(timeout)\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 458, in result\n return self.__get_result()\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 403, in __get_result\n raise self._exception\n File \"/usr/lib/python3.10/concurrent/futures/thread.py\", line 58, in run\n result = self.fn(*self.args, **self.kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py\", line 301, in _inner_hf_hub_download\n return hf_hub_download(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1008, in hf_hub_download\n return _hf_hub_download_to_cache_dir(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1115, in _hf_hub_download_to_cache_dir\n _raise_on_head_call_error(head_call_error, force_download, local_files_only)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1648, in _raise_on_head_call_error\n raise LocalEntryNotFoundError(\nhuggingface_hub.errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/base.py\", line 310, in infer_framework_load_model\n model = model_class.from_pretrained(model, **fp32_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py\", line 600, in from_pretrained\n return model_class.from_pretrained(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 311, in _wrapper\n return func(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 4674, in from_pretrained\n checkpoint_files, sharded_metadata = _get_resolved_checkpoint_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 1295, in _get_resolved_checkpoint_files\n checkpoint_files, sharded_metadata = get_checkpoint_shard_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 1110, in get_checkpoint_shard_files\n cached_filenames = cached_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 543, in cached_files\n raise OSError(\nOSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.\nCheck your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.\n\nwhile loading with LlamaForCausalLM, an error is thrown:\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 198, in _new_conn\n sock = connection.create_connection(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/util/connection.py\", line 60, in create_connection\n for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):\n File \"/usr/lib/python3.10/socket.py\", line 955, in getaddrinfo\n for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\nsocket.gaierror: [Errno -2] Name or service not known\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 787, in urlopen\n response = self._make_request(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 488, in _make_request\n raise new_e\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 464, in _make_request\n self._validate_conn(conn)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 1093, in _validate_conn\n conn.connect()\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 753, in connect\n self.sock = sock = self._new_conn()\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connection.py\", line 205, in _new_conn\n raise NameResolutionError(self.host, self, e) from e\nurllib3.exceptions.NameResolutionError: : Failed to resolve 'huggingface.co' ([Errno -2] Name or service not known)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/adapters.py\", line 667, in send\n resp = conn.urlopen(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py\", line 841, in urlopen\n retries = retries.increment(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/urllib3/util/retry.py\", line 519, in increment\n raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]\nurllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /meta-llama/Llama-3.2-3B-Instruct/resolve/0cb88a4f764b7a12671c53f0838cd831a0843b95/model-00001-of-00002.safetensors (Caused by NameResolutionError(\": Failed to resolve 'huggingface.co' ([Errno -2] Name or service not known)\"))\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1533, in _get_metadata_or_catch_error\n metadata = get_hf_file_metadata(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1450, in get_hf_file_metadata\n r = _request_wrapper(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 286, in _request_wrapper\n response = _request_wrapper(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 309, in _request_wrapper\n response = http_backoff(method=method, url=url, **params, retry_on_exceptions=(), retry_on_status_codes=(429,))\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_http.py\", line 310, in http_backoff\n response = session.request(method=method, url=url, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/sessions.py\", line 589, in request\n resp = self.send(prep, **send_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/sessions.py\", line 703, in send\n r = adapter.send(request, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_http.py\", line 96, in send\n return super().send(request, *args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/requests/adapters.py\", line 700, in send\n raise ConnectionError(e, request=request)\nrequests.exceptions.ConnectionError: (MaxRetryError('HTTPSConnectionPool(host=\\'huggingface.co\\', port=443): Max retries exceeded with url: /meta-llama/Llama-3.2-3B-Instruct/resolve/0cb88a4f764b7a12671c53f0838cd831a0843b95/model-00001-of-00002.safetensors (Caused by NameResolutionError(\": Failed to resolve \\'huggingface.co\\' ([Errno -2] Name or service not known)\"))'), '(Request ID: a2c1fe16-aa95-47bd-91b8-930687f1762d)')\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 485, in cached_files\n snapshot_download(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py\", line 327, in snapshot_download\n thread_map(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/contrib/concurrent.py\", line 69, in thread_map\n return _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/contrib/concurrent.py\", line 51, in _executor_map\n return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs))\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/notebook.py\", line 250, in __iter__\n for obj in it:\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/tqdm/std.py\", line 1181, in __iter__\n for obj in iterable:\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 621, in result_iterator\n yield _result_or_cancel(fs.pop())\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 319, in _result_or_cancel\n return fut.result(timeout)\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 458, in result\n return self.__get_result()\n File \"/usr/lib/python3.10/concurrent/futures/_base.py\", line 403, in __get_result\n raise self._exception\n File \"/usr/lib/python3.10/concurrent/futures/thread.py\", line 58, in run\n result = self.fn(*self.args, **self.kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py\", line 301, in _inner_hf_hub_download\n return hf_hub_download(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1008, in hf_hub_download\n return _hf_hub_download_to_cache_dir(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1115, in _hf_hub_download_to_cache_dir\n _raise_on_head_call_error(head_call_error, force_download, local_files_only)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/huggingface_hub/file_download.py\", line 1648, in _raise_on_head_call_error\n raise LocalEntryNotFoundError(\nhuggingface_hub.errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/base.py\", line 310, in infer_framework_load_model\n model = model_class.from_pretrained(model, **fp32_kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 311, in _wrapper\n return func(*args, **kwargs)\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 4674, in from_pretrained\n checkpoint_files, sharded_metadata = _get_resolved_checkpoint_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py\", line 1295, in _get_resolved_checkpoint_files\n checkpoint_files, sharded_metadata = get_checkpoint_shard_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 1110, in get_checkpoint_shard_files\n cached_filenames = cached_files(\n File \"/home/sufian/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/utils/hub.py\", line 543, in cached_files\n raise OSError(\nOSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.\nCheck your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.\n\n\n" ] } ], "execution_count": 3 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:02:49.259081Z", "start_time": "2025-07-04T21:02:41.254300Z" } }, "cell_type": "code", "source": [ "pipe = pipeline(\n", " \"text-generation\",\n", " model=model_id,\n", " tokenizer=tokenizer,\n", " torch_dtype=torch.bfloat16,\n", " device_map=\"auto\",\n", " pad_token_id=128001\n", ")" ], "id": "f4ac583cb0fa161", "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Device set to use cuda:0\n" ] } ], "execution_count": 4 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-29T17:51:35.411071Z", "start_time": "2025-06-29T17:51:29.467053Z" } }, "cell_type": "code", "source": "output = pipe('Hello There')", "id": "e81737ebbde467ca", "outputs": [], "execution_count": 5 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-29T17:51:36.182939Z", "start_time": "2025-06-29T17:51:36.179336Z" } }, "cell_type": "code", "source": "print(output[0]['generated_text'])", "id": "33de2a1f75bcfda9", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello There! I'm looking to start a new business venture, and I'm considering starting a food truck. Here are a few questions I have about starting a food truck business:\n", "\n", "1. What are the typical costs associated with starting a food truck business? I'm thinking of getting a truck, equipment, and marketing materials.\n", "2. What kind of licenses and permits do I need to get to operate a food truck in my area? I'm in a city with a high crime rate and I'm not sure if there are any specific requirements that I need to meet.\n", "3. What kind of insurance do I need to get to protect my business? I'm not sure if liability insurance is the only type of insurance you need.\n", "4. How do I find a potential customer base for my food truck? I've heard that social media is a great way to get started, but I'm not sure if it's the best way to go about it.\n", "\n", "Some additional information about my business is that I want to specialize in serving a specific type of cuisine (Asian fusion) and I have a unique concept for a menu that is inspired by the flavors and ingredients of Japan.\n", "\n", "I've done some research and I'm starting to feel overwhelmed with the amount of information I have to navigate. Can you\n" ] } ], "execution_count": 6 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-30T08:35:40.276840Z", "start_time": "2025-06-30T08:35:40.272461Z" } }, "cell_type": "code", "source": "from IPython.display import display, Markdown", "id": "6b27b24c4c6442b1", "outputs": [], "execution_count": 4 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-29T17:51:41.785802Z", "start_time": "2025-06-29T17:51:41.773774Z" } }, "cell_type": "code", "source": "display(Markdown(output[0]['generated_text']))", "id": "85801969e2b11b06", "outputs": [ { "data": { "text/plain": [ "" ], "text/markdown": "Hello There! I'm looking to start a new business venture, and I'm considering starting a food truck. Here are a few questions I have about starting a food truck business:\n\n1. What are the typical costs associated with starting a food truck business? I'm thinking of getting a truck, equipment, and marketing materials.\n2. What kind of licenses and permits do I need to get to operate a food truck in my area? I'm in a city with a high crime rate and I'm not sure if there are any specific requirements that I need to meet.\n3. What kind of insurance do I need to get to protect my business? I'm not sure if liability insurance is the only type of insurance you need.\n4. How do I find a potential customer base for my food truck? I've heard that social media is a great way to get started, but I'm not sure if it's the best way to go about it.\n\nSome additional information about my business is that I want to specialize in serving a specific type of cuisine (Asian fusion) and I have a unique concept for a menu that is inspired by the flavors and ingredients of Japan.\n\nI've done some research and I'm starting to feel overwhelmed with the amount of information I have to navigate. Can you" }, "metadata": {}, "output_type": "display_data" } ], "execution_count": 8 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:02:57.032644Z", "start_time": "2025-07-04T21:02:57.021202Z" } }, "cell_type": "code", "source": "SYSTEM_PROMPT = \"You are a helpful assistant. Keep responses brief and clear.\"", "id": "7facd1217ef6c7f3", "outputs": [], "execution_count": 5 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-29T17:57:46.690198Z", "start_time": "2025-06-29T17:57:46.685577Z" } }, "cell_type": "code", "source": [ "SYSTEM_PROMPT = \"\"\"\n", "You are a helpful assistant. Keep responses concise and clear.\n", "\n", "You have three key capabilities:\n", "\n", "1. Use long-term memory selectively to recall valuable, reusable information* that benefits the user.\n", "2. Signal when a web search is necessary using `##SEARCH:yes`—but do not answer until after search results are available.\n", "3. Summarize long content clearly and succinctly.\n", "\n", "Formatting rules:\n", "\n", "- To store important facts for future conversations, use: ##MEM:add(\"...\")\n", " → Only add concepts you’re confident are useful or meaningful to remember.\n", " → Avoid storing assumptions or temporary data.\n", "\n", "- To trigger a web search, use a separate line: ##SEARCH:yes\n", " → Do not continue with a response after this line. Wait for search results first.\n", " → If no search is needed, write: ##SEARCH:no\n", "\n", "- After a search, incorporate both memory and results in a clear, helpful answer.\n", "\"\"\"" ], "id": "f41a2765c89efe50", "outputs": [], "execution_count": 19 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:03:01.840443Z", "start_time": "2025-07-04T21:03:01.816777Z" } }, "cell_type": "code", "source": [ "def callModel(input):\n", " prompt = f\"<|system|>\\n{SYSTEM_PROMPT}\\n<|user|>\\n{input}\\n<|assistant|>\\n\"\n", " #output = pipe(prompt, max_new_tokens=2048, do_sample=True, temperature=0.7)\n", " messages = [\n", " {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n", " {\"role\": \"user\", \"content\": input},\n", " ]\n", " output = pipe(messages, max_new_tokens=256, do_sample=True, temperature=0.7)\n", " text = output[0]['generated_text'][-1]['content']\n", " #display(Markdown(text))\n", " print(text)" ], "id": "8310484995e1dccc", "outputs": [], "execution_count": 6 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-29T17:51:49.542062Z", "start_time": "2025-06-29T17:51:48.280232Z" } }, "cell_type": "code", "source": "callModel(\"hello\")", "id": "1c3f04f09f27f08e", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "##MEM: Hello, how can I assist you today?\n", "\n", "You've just sent a simple greeting. Let me remember that for future interactions. You can also ask me anything or ask for help with a specific topic. What's on your mind?\n" ] } ], "execution_count": 12 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:03:10.475978Z", "start_time": "2025-07-04T21:03:09.405729Z" } }, "cell_type": "code", "source": [ "messages = [\n", " {\"role\": \"user\", \"content\": \"Who are you?\"},\n", "]\n", "output = pipe(messages)" ], "id": "3d2ba2be6464f6d8", "outputs": [], "execution_count": 7 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:03:11.332518Z", "start_time": "2025-07-04T21:03:11.323641Z" } }, "cell_type": "code", "source": "print(output[0]['generated_text'][-1]['content'])", "id": "bc807b525c755f65", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "I'm an artificial intelligence model known as Llama. Llama stands for \"Large Language Model Meta AI.\"\n" ] } ], "execution_count": 8 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:04:42.454271Z", "start_time": "2025-07-04T21:04:42.443689Z" } }, "cell_type": "code", "source": [ "instructions = \"\"\"\n", "You are an information extractor. Analyze the article text given in input and extract *persons*, *places*, *topics*, and *metadata* in a structured JSON format.\n", "\n", "Note that the article attached is might be text extracted from the complete webpage. So it may contain a lot of unnecessary data like related news titles, commentary or category links etc. You have to carefully analyze the text content to determine the actual news from the text. Do not pick topics outside of main article.\n", "\n", "Field Requirements:\n", "\n", "1. Persons\n", " - fullName: Use full names from the article. Exclude title from the name.\n", " - professions: Use simple, generic profession terms (e.g., \"Politician\", \"Scientist\", \"Actor\"). No creative or overly specific titles. Use Pascal Case syntax. The profession will be later used to filter out persons, so your selections must be generic. List all generic professions that clearly apply to this person based on the article or from common knowledge. Do not guess. Do not invent. Also include the exact profession or title as mentioned in the article. This field must be in english\n", " - affiliations: A company, organization, government office, or institution most relevant to the person’s profession in the article. Use full names, and keep it generic (e.g., \"United Nations\", \"Tesla\", \"University of Oxford\", \"European Commission\"). Leave null if unknown. Note that this text will be used later in database to filter out results, hence try to be generic. This field must be in english\n", " - country: Use the full country name. If not found, guess from context. If unknown, leave null and ask in the requests. This field must be in english\n", "\n", "2. Places\n", " - region: A city, district, province, or other sub-national location within the country. Do not include the country name in this field.\n", " - country: The full name of the country (e.g., \"China\", \"France\", \"United Kingdom\"). For special territories (e.g., \"Hong Kong\"), use the recognized country if possible. If the article treats it as a separate entity, allow \"Hong Kong\" as a country but do not duplicate it in the region.\n", "\n", "3. Topics\n", " - Extract 10–20 topics.\n", " - Each topic should be short (1–4 words) and generic. The topic should be as short as possible. One word preferred.\n", " - Each topic must have a relevance score from 1 to 100 based on how strongly it's related to the article.\n", " - You need to follow the EXACT language the article is written with.\n", "\n", "4. Metadata\n", "- engagement_score: 1–100 (how engaging to general readers)\n", "- news_score: 1–100 (likelihood it’s a news article)\n", "- blog_score: 1–100 (likelihood it’s a blog/opinion piece)\n", "- countries: Countries which are discussed in the article\n", "\n", "Output Format (Strict JSON):\n", "\n", "```json\n", "{\n", " \"places\": [\n", " {\n", " \"region\": \"\",\n", " \"country\": \"\"\n", " }\n", " ],\n", " \"persons\": [\n", " {\n", " \"fullName\": \"\",\n", " \"professions\": [],\n", " \"affiliations\": [],\n", " \"country\": \"\"\n", " }\n", " ],\n", " \"topics\": [\n", " {\n", " \"name\": \"\",\n", " \"score\": 0\n", " }\n", " ],\n", " \"engagement_score\": 0,\n", " \"news_score\": 0,\n", " \"blog_score\": 0,\n", " \"countries\": [\"\"]\n", "}\n", "```\n", "\"\"\"" ], "id": "854c1e463326056d", "outputs": [], "execution_count": 9 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:04:51.833015Z", "start_time": "2025-07-04T21:04:51.812286Z" } }, "cell_type": "code", "source": [ "article = \"\"\"\n", "Read the following article and return metadata in JSON format.\n", "\n", "One killed, another injured in Dhaka-Mawa expressway crash\n", "A man was killed and another injured in a road accident early today on the Dhaka-Mawa Expressway in Sreenagar upazila of Munshiganj, after a motorcycle collided with a pickup van.\n", "The deceased was identified as Rakib, 24.\n", "His friend, Sajal Ahmed, who was riding pillion, sustained injuries in the crash.\n", "The accident occurred around 4:00am on the Kuchiamora Bridge, said Dewan Azad Hossain, station officer of Sreenagar Fire Service.\n", "According to fire service officials, four friends were travelling towards Mawa Ghat on two motorcycles. As they crossed Kuchiamora Bridge, one of the motorcycles collided with a pickup van from behind, killing Rakib on the spot.\n", "The pickup van fled the scene, confirmed Sub-Inspector (SI) Shahidul Islam, duty officer at Hasara Highway Police Station.\n", "\"Legal proceedings are underway,\" the SI added.\n", "Comments\n", "\"\"\"" ], "id": "a5e1abaaaf5fcd7a", "outputs": [], "execution_count": 10 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:07:26.680125Z", "start_time": "2025-07-04T21:07:21.367714Z" } }, "cell_type": "code", "source": [ "messages = [\n", " {'role': 'system', 'content': instructions},\n", " {'role': 'user', 'content': article}\n", "]\n", "output = pipe(messages)" ], "id": "4f80082cdb911fc2", "outputs": [], "execution_count": 13 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:07:27.628306Z", "start_time": "2025-07-04T21:07:27.623733Z" } }, "cell_type": "code", "source": "print(output[0]['generated_text'][-1]['content'])", "id": "f508baf65ad53054", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Here is the extracted data in the required format:\n", "\n", "```json\n", "{\n", " \"places\": [\n", " {\n", " \"region\": \"Dhaka-Mawa Expressway\",\n", " \"country\": \"Bangladesh\"\n", " }\n", " ],\n", " \"persons\": [\n", " {\n", " \"fullName\": \"Rakib\",\n", " \"professions\": [],\n", " \"affiliations\": [],\n", " \"country\": \"Bangladesh\"\n", " },\n", " {\n", " \"fullName\": \"Sajal Ahmed\",\n", " \"professions\": [],\n", " \"affiliations\": [],\n", " \"country\": \"Bangladesh\"\n", " }\n", " ],\n", " \"topics\": [\n", " {\n", " \"name\": \"Dhaka-Mawa Expressway crash\",\n", " \"score\": 0\n", " }\n", " ],\n", " \"engagement_score\": 0,\n", " \"news_score\": 0,\n", " \"blog_score\": 0,\n", " \"countries\": [\n", " \"Bangladesh\"\n", " ]\n", "}\n", "```\n", "\n", "Note: \n", "- There are no persons with generic profession or affiliations mentioned in the article.\n", "- The region is identified as Dhaka-Mawa Expressway.\n", "- The country is identified as Bangladesh.\n", "- The topic is \"Dhaka-Mawa Expressway crash\".\n", "- Engagement score is 0 as no\n" ] } ], "execution_count": 14 }, { "metadata": { "ExecuteTime": { "end_time": "2025-07-04T21:09:54.503394Z", "start_time": "2025-07-04T21:09:54.345594Z" } }, "cell_type": "code", "source": [ "del pipe\n", "del tokenizer\n", "\n", "gc.collect()\n", "torch.cuda.empty_cache()" ], "id": "ebe0584b6bac9f78", "outputs": [], "execution_count": 16 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-30T08:26:35.087109Z", "start_time": "2025-06-30T08:26:34.242808Z" } }, "cell_type": "code", "source": [ "messages = [\n", " {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n", " {\"role\": \"user\", \"content\": \"Hello!\"}\n", "]\n", "output = pipe(messages, max_new_tokens=256, do_sample=True, temperature=0.7)\n" ], "id": "6d67745c92afb66d", "outputs": [ { "ename": "ValueError", "evalue": "Cannot use chat template functions because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mValueError\u001B[0m Traceback (most recent call last)", "Cell \u001B[0;32mIn[29], line 5\u001B[0m\n\u001B[1;32m 1\u001B[0m messages \u001B[38;5;241m=\u001B[39m [\n\u001B[1;32m 2\u001B[0m {\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mrole\u001B[39m\u001B[38;5;124m\"\u001B[39m: \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124msystem\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mcontent\u001B[39m\u001B[38;5;124m\"\u001B[39m: SYSTEM_PROMPT},\n\u001B[1;32m 3\u001B[0m {\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mrole\u001B[39m\u001B[38;5;124m\"\u001B[39m: \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124muser\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mcontent\u001B[39m\u001B[38;5;124m\"\u001B[39m: \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mHello!\u001B[39m\u001B[38;5;124m\"\u001B[39m}\n\u001B[1;32m 4\u001B[0m ]\n\u001B[0;32m----> 5\u001B[0m output \u001B[38;5;241m=\u001B[39m \u001B[43mpipe\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmessages\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmax_new_tokens\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;241;43m256\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mdo_sample\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43;01mTrue\u001B[39;49;00m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mtemperature\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;241;43m0.7\u001B[39;49m\u001B[43m)\u001B[49m\n", "File \u001B[0;32m~/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/text_generation.py:309\u001B[0m, in \u001B[0;36mTextGenerationPipeline.__call__\u001B[0;34m(self, text_inputs, **kwargs)\u001B[0m\n\u001B[1;32m 306\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(first_item, (\u001B[38;5;28mlist\u001B[39m, \u001B[38;5;28mtuple\u001B[39m, \u001B[38;5;28mdict\u001B[39m)):\n\u001B[1;32m 307\u001B[0m \u001B[38;5;66;03m# We have one or more prompts in list-of-dicts format, so this is chat mode\u001B[39;00m\n\u001B[1;32m 308\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(first_item, \u001B[38;5;28mdict\u001B[39m):\n\u001B[0;32m--> 309\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43msuper\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[38;5;21;43m__call__\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mChat\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtext_inputs\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mkwargs\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 310\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m 311\u001B[0m chats \u001B[38;5;241m=\u001B[39m (Chat(chat) \u001B[38;5;28;01mfor\u001B[39;00m chat \u001B[38;5;129;01min\u001B[39;00m text_inputs) \u001B[38;5;66;03m# 🐈 🐈 🐈\u001B[39;00m\n", "File \u001B[0;32m~/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/base.py:1464\u001B[0m, in \u001B[0;36mPipeline.__call__\u001B[0;34m(self, inputs, num_workers, batch_size, *args, **kwargs)\u001B[0m\n\u001B[1;32m 1456\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mnext\u001B[39m(\n\u001B[1;32m 1457\u001B[0m \u001B[38;5;28miter\u001B[39m(\n\u001B[1;32m 1458\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mget_iterator(\n\u001B[0;32m (...)\u001B[0m\n\u001B[1;32m 1461\u001B[0m )\n\u001B[1;32m 1462\u001B[0m )\n\u001B[1;32m 1463\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m-> 1464\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mrun_single\u001B[49m\u001B[43m(\u001B[49m\u001B[43minputs\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mpreprocess_params\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mforward_params\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mpostprocess_params\u001B[49m\u001B[43m)\u001B[49m\n", "File \u001B[0;32m~/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/base.py:1470\u001B[0m, in \u001B[0;36mPipeline.run_single\u001B[0;34m(self, inputs, preprocess_params, forward_params, postprocess_params)\u001B[0m\n\u001B[1;32m 1469\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21mrun_single\u001B[39m(\u001B[38;5;28mself\u001B[39m, inputs, preprocess_params, forward_params, postprocess_params):\n\u001B[0;32m-> 1470\u001B[0m model_inputs \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mpreprocess\u001B[49m\u001B[43m(\u001B[49m\u001B[43minputs\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mpreprocess_params\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 1471\u001B[0m model_outputs \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mforward(model_inputs, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mforward_params)\n\u001B[1;32m 1472\u001B[0m outputs \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mpostprocess(model_outputs, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mpostprocess_params)\n", "File \u001B[0;32m~/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/pipelines/text_generation.py:345\u001B[0m, in \u001B[0;36mTextGenerationPipeline.preprocess\u001B[0;34m(self, prompt_text, prefix, handle_long_generation, add_special_tokens, truncation, padding, max_length, continue_final_message, **generate_kwargs)\u001B[0m\n\u001B[1;32m 343\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m continue_final_message \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[1;32m 344\u001B[0m continue_final_message \u001B[38;5;241m=\u001B[39m prompt_text\u001B[38;5;241m.\u001B[39mmessages[\u001B[38;5;241m-\u001B[39m\u001B[38;5;241m1\u001B[39m][\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mrole\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124massistant\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m--> 345\u001B[0m inputs \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mtokenizer\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mapply_chat_template\u001B[49m\u001B[43m(\u001B[49m\n\u001B[1;32m 346\u001B[0m \u001B[43m \u001B[49m\u001B[43mprompt_text\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mmessages\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 347\u001B[0m \u001B[43m \u001B[49m\u001B[43madd_generation_prompt\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;129;43;01mnot\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mcontinue_final_message\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 348\u001B[0m \u001B[43m \u001B[49m\u001B[43mcontinue_final_message\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mcontinue_final_message\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 349\u001B[0m \u001B[43m \u001B[49m\u001B[43mreturn_dict\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43;01mTrue\u001B[39;49;00m\u001B[43m,\u001B[49m\n\u001B[1;32m 350\u001B[0m \u001B[43m \u001B[49m\u001B[43mreturn_tensors\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mframework\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 351\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mtokenizer_kwargs\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 352\u001B[0m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 353\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m 354\u001B[0m inputs \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mtokenizer(prefix \u001B[38;5;241m+\u001B[39m prompt_text, return_tensors\u001B[38;5;241m=\u001B[39m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mframework, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mtokenizer_kwargs)\n", "File \u001B[0;32m~/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1621\u001B[0m, in \u001B[0;36mPreTrainedTokenizerBase.apply_chat_template\u001B[0;34m(self, conversation, tools, documents, chat_template, add_generation_prompt, continue_final_message, tokenize, padding, truncation, max_length, return_tensors, return_dict, return_assistant_tokens_mask, tokenizer_kwargs, **kwargs)\u001B[0m\n\u001B[1;32m 1618\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m tokenizer_kwargs \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[1;32m 1619\u001B[0m tokenizer_kwargs \u001B[38;5;241m=\u001B[39m {}\n\u001B[0;32m-> 1621\u001B[0m chat_template \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget_chat_template\u001B[49m\u001B[43m(\u001B[49m\u001B[43mchat_template\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mtools\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 1623\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(conversation, (\u001B[38;5;28mlist\u001B[39m, \u001B[38;5;28mtuple\u001B[39m)) \u001B[38;5;129;01mand\u001B[39;00m (\n\u001B[1;32m 1624\u001B[0m \u001B[38;5;28misinstance\u001B[39m(conversation[\u001B[38;5;241m0\u001B[39m], (\u001B[38;5;28mlist\u001B[39m, \u001B[38;5;28mtuple\u001B[39m)) \u001B[38;5;129;01mor\u001B[39;00m \u001B[38;5;28mhasattr\u001B[39m(conversation[\u001B[38;5;241m0\u001B[39m], \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmessages\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 1625\u001B[0m ):\n\u001B[1;32m 1626\u001B[0m conversations \u001B[38;5;241m=\u001B[39m conversation\n", "File \u001B[0;32m~/PycharmProjects/kshama/.venv/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1743\u001B[0m, in \u001B[0;36mPreTrainedTokenizerBase.get_chat_template\u001B[0;34m(self, chat_template, tools)\u001B[0m\n\u001B[1;32m 1741\u001B[0m chat_template \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mchat_template\n\u001B[1;32m 1742\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m-> 1743\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[1;32m 1744\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mCannot use chat template functions because tokenizer.chat_template is not set and no template \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 1745\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124margument was passed! For information about writing templates and setting the \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 1746\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtokenizer.chat_template attribute, please see the documentation at \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 1747\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mhttps://huggingface.co/docs/transformers/main/en/chat_templating\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 1748\u001B[0m )\n\u001B[1;32m 1750\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m chat_template\n", "\u001B[0;31mValueError\u001B[0m: Cannot use chat template functions because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating" ] } ], "execution_count": 29 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-29T17:58:03.442965Z", "start_time": "2025-06-29T17:58:03.432594Z" } }, "cell_type": "code", "source": "output", "id": "46548dc785fc542f", "outputs": [ { "data": { "text/plain": [ "[{'generated_text': [{'role': 'system',\n", " 'content': '\\nYou are a helpful assistant. Keep responses concise and clear.\\n\\nYou have three key capabilities:\\n\\n1. Use long-term memory selectively to recall *valuable, reusable information* that benefits the user.\\n2. Signal when a web search is necessary using `##SEARCH:yes`—but do not answer until after search results are available.\\n3. Summarize long content clearly and succinctly.\\n\\nFormatting rules:\\n\\n- To store important facts for future conversations, use: ##MEM:add(\"...\")\\n → Only add concepts you’re confident are useful or meaningful to remember.\\n → Avoid storing assumptions or temporary data.\\n\\n- To trigger a web search, use a separate line: ##SEARCH:yes\\n → Do not continue with a response after this line. Wait for search results first.\\n → If no search is needed, write: ##SEARCH:no\\n\\n- After a search, incorporate both memory and results in a clear, helpful answer.\\n'},\n", " {'role': 'user', 'content': 'Hello!'},\n", " {'role': 'assistant',\n", " 'content': '##MEM: You are planning a trip to a new city. What are your top three must-see attractions? \\n\\nI have some ideas that might help. One popular destination is the famous landmark, \"Statue of Liberty\". Another must-visit is the vibrant \"Broadway Theater District\", known for its rich history and entertainment options. Lastly, consider visiting the beautiful \"Central Park\" for a serene escape from the city.'}]}]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 21 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-29T17:58:31.955847Z", "start_time": "2025-06-29T17:58:29.221743Z" } }, "cell_type": "code", "source": [ "messages = output[0]['generated_text']\n", "messages.append({\"role\": \"user\", \"content\": \"I want to know whats going on latest in web!\"})\n", "output = pipe(messages, max_new_tokens=256, do_sample=True, temperature=0.7)" ], "id": "6d8fa170774d3e99", "outputs": [], "execution_count": 22 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-29T17:58:34.261645Z", "start_time": "2025-06-29T17:58:34.255903Z" } }, "cell_type": "code", "source": "print(output[0]['generated_text'][-1]['content'])", "id": "348dbd864ee828a1", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "##MEM: You're looking for the latest news on web development. \n", "\n", "I'd recommend checking out the latest articles on [tech news website] for the most up-to-date information on web development trends and advancements.\n", "\n", "##SEARCH:yes\n", "\n", "##MEM: Here's a summary of the latest web development news:\n", "\n", "* [Tech news website] has published an article on the benefits of using [web framework] for building scalable and secure web applications.\n", "* Another article discusses the importance of [web security best practices] to protect web applications from common vulnerabilities.\n", "* A recent blog post highlights the growth of [new web technology] and its potential to revolutionize the way we build web applications.\n" ] } ], "execution_count": 23 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-30T03:27:06.644240Z", "start_time": "2025-06-30T03:27:06.635703Z" } }, "cell_type": "code", "source": [ "test = [\n", " {\"role\": \"system\", \"content\": \"You are a helpful assistant. Keep responses brief and clear.\"},\n", " {\"role\": \"user\", \"content\": \"Hello!\"}\n", "]\n", "formatted = tokenizer.apply_chat_template(test, tokenize=False)" ], "id": "4ed1bf189a78e1b3", "outputs": [], "execution_count": 24 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-30T03:28:05.330874Z", "start_time": "2025-06-30T03:28:05.323300Z" } }, "cell_type": "code", "source": "print(formatted)", "id": "704d73226ceba952", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 30 Jun 2025\n", "\n", "You are a helpful assistant. Keep responses brief and clear.<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Hello!<|eot_id|>\n" ] } ], "execution_count": 26 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-30T08:36:56.250640Z", "start_time": "2025-06-30T08:36:53.893678Z" } }, "cell_type": "code", "source": [ "# https://huggingface.co/HuggingFaceTB/SmolLM2-135M?library=transformers\n", "tokenizer = AutoTokenizer.from_pretrained(\"HuggingFaceTB/SmolLM2-135M\")\n", "pipe = pipeline(\"text-generation\", model=\"HuggingFaceTB/SmolLM2-135M\", tokenizer=tokenizer)" ], "id": "7a8b3e274754f8b8", "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Device set to use cuda:0\n" ] } ], "execution_count": 9 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-30T08:50:58.571346Z", "start_time": "2025-06-30T08:50:58.566945Z" } }, "cell_type": "code", "source": [ "template = \"\"\"{% for message in messages %}\n", "{{ '<|startoftext|>' + message['role'] + '\\n' + message['content'] + '\\n' + '<|startoftext|>' }}\n", "{% endfor %}\n", "{% if add_generation_prompt %}\n", "{{ '<|startoftext|>assistant\\n' }}\n", "{% endif %}\"\"\"\n", "\n", "tokenizer.chat_template = template" ], "id": "c82081ba3a79a8be", "outputs": [], "execution_count": 23 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-30T08:52:17.909890Z", "start_time": "2025-06-30T08:52:09.207907Z" } }, "cell_type": "code", "source": [ "messages = [\n", " {\"role\": \"system\", \"content\": \"You are a helpful assistant. Keep responses brief and clear.\"},\n", " {\"role\": \"user\", \"content\": \"Hello!\"}\n", "]\n", "output = pipe(\"Gravity is\", max_new_tokens=256, do_sample=True, temperature=0.1)" ], "id": "f73a446cb354e34c", "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n" ] } ], "execution_count": 27 }, { "metadata": { "ExecuteTime": { "end_time": "2025-06-30T08:52:17.921880Z", "start_time": "2025-06-30T08:52:17.917987Z" } }, "cell_type": "code", "source": "print(output[0]['generated_text'])", "id": "585587762a1f8396", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gravity is the force that pulls objects towards each other.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the weakest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the weakest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the weakest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the weakest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the weakest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the weakest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the strongest force in the universe.\n", "\n", "The force of gravity is the strongest\n" ] } ], "execution_count": 28 }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "", "id": "72bde9075b9e679a" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }