unsloth icon indicating copy to clipboard operation
unsloth copied to clipboard

how to download model,and use offline model

Open qingxin113-1 opened this issue 1 year ago • 2 comments

code:

from unsloth import FastLanguageModel
import torch
max_seq_length = 2048
dtype = None
load_in_4bit = True
fourbit_models = [
    "unsloth/mistral-7b-bnb-4bit",
    "unsloth/mistral-7b-instruct-v0.2-bnb-4bit",
    "unsloth/llama-2-7b-bnb-4bit",
    "unsloth/gemma-7b-bnb-4bit",
    "unsloth/gemma-7b-it-bnb-4bit", 
    "unsloth/gemma-2b-bnb-4bit",
    "unsloth/gemma-2b-it-bnb-4bit",
    "unsloth/llama-3-8b-bnb-4bit", 
]

model, tokenizer = FastLanguageModel.from_pretrained(
    pretrained_model_name_or_path = "/home/sr/projects/llama3/llama-3-8b-bnb-4bi",
    #model_name = "unsloth/llama-3-8b-bnb-4bit",
    max_seq_length = max_seq_length,
    dtype = dtype,
    load_in_4bit = load_in_4bit,
    local_files_only = True,
)
)

the dir of "/home/sr/projects/llama3/llama-3-8b-bnb-4bi" has 8 files:config.json,LICENSE, README.md, tokenizer_config.json,generation_config.json,model.safetensors ,special_tokens_map.json,tokenizer.json the model is used by command download:export HF_ENDPOINT=https://hf-mirror.com huggingface-cli download unsloth/llama-3-8b-bnb-4bit --resume-download --local-dir llama-3-8b-bnb-4bit error:

OSError                                   Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connection.py:198, in HTTPConnection._new_conn(self)
    197 try:
--> 198     sock = connection.create_connection(
    199         (self._dns_host, self.port),
    200         self.timeout,
    201         source_address=self.source_address,
    202         socket_options=self.socket_options,
    203     )
    204 except socket.gaierror as e:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/util/connection.py:85, in create_connection(address, timeout, source_address, socket_options)
     84 try:
---> 85     raise err
     86 finally:
     87     # Break explicitly a reference cycle

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/util/connection.py:73, in create_connection(address, timeout, source_address, socket_options)
     72     sock.bind(source_address)
---> 73 sock.connect(sa)
     74 # Break explicitly a reference cycle

OSError: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

NewConnectionError                        Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:793, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    792 # Make the request on the HTTPConnection object
--> 793 response = self._make_request(
    794     conn,
    795     method,
    796     url,
    797     timeout=timeout_obj,
    798     body=body,
    799     headers=headers,
    800     chunked=chunked,
    801     retries=retries,
    802     response_conn=response_conn,
    803     preload_content=preload_content,
    804     decode_content=decode_content,
    805     **response_kw,
    806 )
    808 # Everything went great!

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:491, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    490         new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
--> 491     raise new_e
    493 # conn.request() calls http.client.*.request, not the method in
    494 # urllib3.request. It also calls makefile (recv) on the socket.

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:467, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    466 try:
--> 467     self._validate_conn(conn)
    468 except (SocketTimeout, BaseSSLError) as e:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:1099, in HTTPSConnectionPool._validate_conn(self, conn)
   1098 if conn.is_closed:
-> 1099     conn.connect()
   1101 # TODO revise this, see https://github.com/urllib3/urllib3/issues/2791

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connection.py:616, in HTTPSConnection.connect(self)
    615 sock: socket.socket | ssl.SSLSocket
--> 616 self.sock = sock = self._new_conn()
    617 server_hostname: str = self.host

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connection.py:213, in HTTPConnection._new_conn(self)
    212 except OSError as e:
--> 213     raise NewConnectionError(
    214         self, f"Failed to establish a new connection: {e}"
    215     ) from e
    217 # Audit hooks are only available in Python 3.8+

NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7d503a07f0a0>: Failed to establish a new connection: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

MaxRetryError                             Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/requests/adapters.py:486, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    485 try:
--> 486     resp = conn.urlopen(
    487         method=request.method,
    488         url=url,
    489         body=request.body,
    490         headers=request.headers,
    491         redirect=False,
    492         assert_same_host=False,
    493         preload_content=False,
    494         decode_content=False,
    495         retries=self.max_retries,
    496         timeout=timeout,
    497         chunked=chunked,
    498     )
    500 except (ProtocolError, OSError) as err:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:847, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    845     new_e = ProtocolError("Connection aborted.", new_e)
--> 847 retries = retries.increment(
    848     method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    849 )
    850 retries.sleep()

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/util/retry.py:515, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
    514     reason = error or ResponseError(cause)
--> 515     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    517 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /unsloth/llama-3-8b-bnb-4bit/resolve/main/config.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7d503a07f0a0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1722, in _get_metadata_or_catch_error(repo_id, filename, repo_type, revision, endpoint, proxies, etag_timeout, headers, local_files_only, relative_filename, storage_folder)
   1721 try:
-> 1722     metadata = get_hf_file_metadata(url=url, proxies=proxies, timeout=etag_timeout, headers=headers)
   1723 except EntryNotFoundError as http_error:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1645, in get_hf_file_metadata(url, token, proxies, timeout, library_name, library_version, user_agent, headers)
   1644 # Retrieve metadata
-> 1645 r = _request_wrapper(
   1646     method="HEAD",
   1647     url=url,
   1648     headers=headers,
   1649     allow_redirects=False,
   1650     follow_relative_redirects=True,
   1651     proxies=proxies,
   1652     timeout=timeout,
   1653 )
   1654 hf_raise_for_status(r)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:372, in _request_wrapper(method, url, follow_relative_redirects, **params)
    371 if follow_relative_redirects:
--> 372     response = _request_wrapper(
    373         method=method,
    374         url=url,
    375         follow_relative_redirects=False,
    376         **params,
    377     )
    379     # If redirection, we redirect only relative paths.
    380     # This is useful in case of a renamed repository.

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:395, in _request_wrapper(method, url, follow_relative_redirects, **params)
    394 # Perform request and return if status_code is not in the retry list.
--> 395 response = get_session().request(method=method, url=url, **params)
    396 hf_raise_for_status(response)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
    591 return resp

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)
    702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
    705 # Total elapsed time of the request (approximately)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/utils/_http.py:66, in UniqueRequestIdAdapter.send(self, request, *args, **kwargs)
     65 try:
---> 66     return super().send(request, *args, **kwargs)
     67 except requests.RequestException as e:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/requests/adapters.py:519, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    517         raise SSLError(e, request=request)
--> 519     raise ConnectionError(e, request=request)
    521 except ClosedPoolError as e:

ConnectionError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /unsloth/llama-3-8b-bnb-4bit/resolve/main/config.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7d503a07f0a0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))"), '(Request ID: 6357a3ab-a587-413a-8d5a-a11f12e657a8)')

The above exception was the direct cause of the following exception:

LocalEntryNotFoundError                   Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/transformers/utils/hub.py:398, in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_gated_repo, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)
    396 try:
    397     # Load from URL or cache if already cached
--> 398     resolved_file = hf_hub_download(
    399         path_or_repo_id,
    400         filename,
    401         subfolder=None if len(subfolder) == 0 else subfolder,
    402         repo_type=repo_type,
    403         revision=revision,
    404         cache_dir=cache_dir,
    405         user_agent=user_agent,
    406         force_download=force_download,
    407         proxies=proxies,
    408         resume_download=resume_download,
    409         token=token,
    410         local_files_only=local_files_only,
    411     )
    412 except GatedRepoError as e:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1221, in hf_hub_download(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, local_dir, user_agent, force_download, proxies, etag_timeout, token, local_files_only, headers, endpoint, legacy_cache_layout, resume_download, force_filename, local_dir_use_symlinks)
   1220 else:
-> 1221     return _hf_hub_download_to_cache_dir(
   1222         # Destination
   1223         cache_dir=cache_dir,
   1224         # File info
   1225         repo_id=repo_id,
   1226         filename=filename,
   1227         repo_type=repo_type,
   1228         revision=revision,
   1229         # HTTP info
   1230         headers=headers,
   1231         proxies=proxies,
   1232         etag_timeout=etag_timeout,
   1233         endpoint=endpoint,
   1234         # Additional options
   1235         local_files_only=local_files_only,
   1236         force_download=force_download,
   1237     )

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1325, in _hf_hub_download_to_cache_dir(cache_dir, repo_id, filename, repo_type, revision, headers, proxies, etag_timeout, endpoint, local_files_only, force_download)
   1324     # Otherwise, raise appropriate error
-> 1325     _raise_on_head_call_error(head_call_error, force_download, local_files_only)
   1327 # From now on, etag, commit_hash, url and size are not None.

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1826, in _raise_on_head_call_error(head_call_error, force_download, local_files_only)
   1824 else:
   1825     # Otherwise: most likely a connection issue or Hub downtime => let's warn the user
-> 1826     raise LocalEntryNotFoundError(
   1827         "An error happened while trying to locate the file on the Hub and we cannot find the requested files"
   1828         " in the local cache. Please check your connection and try again or make sure your Internet connection"
   1829         " is on."
   1830     ) from head_call_error

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.

The above exception was the direct cause of the following exception:

OSError                                   Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/unsloth/models/loader.py:95, in FastLanguageModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, token, device_map, rope_scaling, fix_tokenizer, trust_remote_code, use_gradient_checkpointing, resize_model_vocab, *args, **kwargs)
     94 try:
---> 95     model_config = AutoConfig.from_pretrained(model_name, token = token)
     96     is_peft = False

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py:928, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
    926 code_revision = kwargs.pop("code_revision", None)
--> 928 config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
    929 has_remote_code = "auto_map" in config_dict and "AutoConfig" in config_dict["auto_map"]

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/transformers/configuration_utils.py:631, in PretrainedConfig.get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
    630 # Get config dict associated with the base config file
--> 631 config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
    632 if "_commit_hash" in config_dict:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/transformers/configuration_utils.py:686, in PretrainedConfig._get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
    684 try:
    685     # Load from local folder or from cache or download from model Hub and cache
--> 686     resolved_config_file = cached_file(
    687         pretrained_model_name_or_path,
    688         configuration_file,
    689         cache_dir=cache_dir,
    690         force_download=force_download,
    691         proxies=proxies,
    692         resume_download=resume_download,
    693         local_files_only=local_files_only,
    694         token=token,
    695         user_agent=user_agent,
    696         revision=revision,
    697         subfolder=subfolder,
    698         _commit_hash=commit_hash,
    699     )
    700     commit_hash = extract_commit_hash(resolved_config_file, commit_hash)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/transformers/utils/hub.py:441, in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_gated_repo, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)
    440         return resolved_file
--> 441     raise EnvironmentError(
    442         f"We couldn't connect to '{HUGGINGFACE_CO_RESOLVE_ENDPOINT}' to load this file, couldn't find it in the"
    443         f" cached files and it looks like {path_or_repo_id} is not the path to a directory containing a file named"
    444         f" {full_filename}.\nCheckout your internet connection or see how to run the library in offline mode at"
    445         " 'https://huggingface.co/docs/transformers/installation#offline-mode'."
    446     ) from e
    447 except EntryNotFoundError as e:

OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like unsloth/llama-3-8b-bnb-4bit is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connection.py:198, in HTTPConnection._new_conn(self)
    197 try:
--> 198     sock = connection.create_connection(
    199         (self._dns_host, self.port),
    200         self.timeout,
    201         source_address=self.source_address,
    202         socket_options=self.socket_options,
    203     )
    204 except socket.gaierror as e:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/util/connection.py:85, in create_connection(address, timeout, source_address, socket_options)
     84 try:
---> 85     raise err
     86 finally:
     87     # Break explicitly a reference cycle

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/util/connection.py:73, in create_connection(address, timeout, source_address, socket_options)
     72     sock.bind(source_address)
---> 73 sock.connect(sa)
     74 # Break explicitly a reference cycle

OSError: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

NewConnectionError                        Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:793, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    792 # Make the request on the HTTPConnection object
--> 793 response = self._make_request(
    794     conn,
    795     method,
    796     url,
    797     timeout=timeout_obj,
    798     body=body,
    799     headers=headers,
    800     chunked=chunked,
    801     retries=retries,
    802     response_conn=response_conn,
    803     preload_content=preload_content,
    804     decode_content=decode_content,
    805     **response_kw,
    806 )
    808 # Everything went great!

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:491, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    490         new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
--> 491     raise new_e
    493 # conn.request() calls http.client.*.request, not the method in
    494 # urllib3.request. It also calls makefile (recv) on the socket.

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:467, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    466 try:
--> 467     self._validate_conn(conn)
    468 except (SocketTimeout, BaseSSLError) as e:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:1099, in HTTPSConnectionPool._validate_conn(self, conn)
   1098 if conn.is_closed:
-> 1099     conn.connect()
   1101 # TODO revise this, see https://github.com/urllib3/urllib3/issues/2791

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connection.py:616, in HTTPSConnection.connect(self)
    615 sock: socket.socket | ssl.SSLSocket
--> 616 self.sock = sock = self._new_conn()
    617 server_hostname: str = self.host

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connection.py:213, in HTTPConnection._new_conn(self)
    212 except OSError as e:
--> 213     raise NewConnectionError(
    214         self, f"Failed to establish a new connection: {e}"
    215     ) from e
    217 # Audit hooks are only available in Python 3.8+

NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7d4f3dddf550>: Failed to establish a new connection: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

MaxRetryError                             Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/requests/adapters.py:486, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    485 try:
--> 486     resp = conn.urlopen(
    487         method=request.method,
    488         url=url,
    489         body=request.body,
    490         headers=request.headers,
    491         redirect=False,
    492         assert_same_host=False,
    493         preload_content=False,
    494         decode_content=False,
    495         retries=self.max_retries,
    496         timeout=timeout,
    497         chunked=chunked,
    498     )
    500 except (ProtocolError, OSError) as err:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/connectionpool.py:847, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    845     new_e = ProtocolError("Connection aborted.", new_e)
--> 847 retries = retries.increment(
    848     method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    849 )
    850 retries.sleep()

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/urllib3/util/retry.py:515, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
    514     reason = error or ResponseError(cause)
--> 515     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    517 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /unsloth/llama-3-8b-bnb-4bit/resolve/main/adapter_config.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7d4f3dddf550>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1722, in _get_metadata_or_catch_error(repo_id, filename, repo_type, revision, endpoint, proxies, etag_timeout, headers, local_files_only, relative_filename, storage_folder)
   1721 try:
-> 1722     metadata = get_hf_file_metadata(url=url, proxies=proxies, timeout=etag_timeout, headers=headers)
   1723 except EntryNotFoundError as http_error:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1645, in get_hf_file_metadata(url, token, proxies, timeout, library_name, library_version, user_agent, headers)
   1644 # Retrieve metadata
-> 1645 r = _request_wrapper(
   1646     method="HEAD",
   1647     url=url,
   1648     headers=headers,
   1649     allow_redirects=False,
   1650     follow_relative_redirects=True,
   1651     proxies=proxies,
   1652     timeout=timeout,
   1653 )
   1654 hf_raise_for_status(r)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:372, in _request_wrapper(method, url, follow_relative_redirects, **params)
    371 if follow_relative_redirects:
--> 372     response = _request_wrapper(
    373         method=method,
    374         url=url,
    375         follow_relative_redirects=False,
    376         **params,
    377     )
    379     # If redirection, we redirect only relative paths.
    380     # This is useful in case of a renamed repository.

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:395, in _request_wrapper(method, url, follow_relative_redirects, **params)
    394 # Perform request and return if status_code is not in the retry list.
--> 395 response = get_session().request(method=method, url=url, **params)
    396 hf_raise_for_status(response)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
    591 return resp

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)
    702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
    705 # Total elapsed time of the request (approximately)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/utils/_http.py:66, in UniqueRequestIdAdapter.send(self, request, *args, **kwargs)
     65 try:
---> 66     return super().send(request, *args, **kwargs)
     67 except requests.RequestException as e:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/requests/adapters.py:519, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    517         raise SSLError(e, request=request)
--> 519     raise ConnectionError(e, request=request)
    521 except ClosedPoolError as e:

ConnectionError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /unsloth/llama-3-8b-bnb-4bit/resolve/main/adapter_config.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7d4f3dddf550>: Failed to establish a new connection: [Errno 101] Network is unreachable'))"), '(Request ID: 6c22d6bd-ad91-42ad-9d79-b513d822eb8d)')

The above exception was the direct cause of the following exception:

LocalEntryNotFoundError                   Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/peft/config.py:144, in PeftConfigMixin.from_pretrained(cls, pretrained_model_name_or_path, subfolder, **kwargs)
    143 try:
--> 144     config_file = hf_hub_download(
    145         pretrained_model_name_or_path, CONFIG_NAME, subfolder=subfolder, **hf_hub_download_kwargs
    146     )
    147 except Exception:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1221, in hf_hub_download(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, local_dir, user_agent, force_download, proxies, etag_timeout, token, local_files_only, headers, endpoint, legacy_cache_layout, resume_download, force_filename, local_dir_use_symlinks)
   1220 else:
-> 1221     return _hf_hub_download_to_cache_dir(
   1222         # Destination
   1223         cache_dir=cache_dir,
   1224         # File info
   1225         repo_id=repo_id,
   1226         filename=filename,
   1227         repo_type=repo_type,
   1228         revision=revision,
   1229         # HTTP info
   1230         headers=headers,
   1231         proxies=proxies,
   1232         etag_timeout=etag_timeout,
   1233         endpoint=endpoint,
   1234         # Additional options
   1235         local_files_only=local_files_only,
   1236         force_download=force_download,
   1237     )

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1325, in _hf_hub_download_to_cache_dir(cache_dir, repo_id, filename, repo_type, revision, headers, proxies, etag_timeout, endpoint, local_files_only, force_download)
   1324     # Otherwise, raise appropriate error
-> 1325     _raise_on_head_call_error(head_call_error, force_download, local_files_only)
   1327 # From now on, etag, commit_hash, url and size are not None.

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/huggingface_hub/file_download.py:1826, in _raise_on_head_call_error(head_call_error, force_download, local_files_only)
   1824 else:
   1825     # Otherwise: most likely a connection issue or Hub downtime => let's warn the user
-> 1826     raise LocalEntryNotFoundError(
   1827         "An error happened while trying to locate the file on the Hub and we cannot find the requested files"
   1828         " in the local cache. Please check your connection and try again or make sure your Internet connection"
   1829         " is on."
   1830     ) from head_call_error

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.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/unsloth/models/loader.py:100, in FastLanguageModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, token, device_map, rope_scaling, fix_tokenizer, trust_remote_code, use_gradient_checkpointing, resize_model_vocab, *args, **kwargs)
     98 try:
     99     # Most likely a PEFT model
--> 100     peft_config = PeftConfig.from_pretrained(model_name, token = token)
    101 except:

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/peft/config.py:148, in PeftConfigMixin.from_pretrained(cls, pretrained_model_name_or_path, subfolder, **kwargs)
    147     except Exception:
--> 148         raise ValueError(f"Can't find '{CONFIG_NAME}' at '{pretrained_model_name_or_path}'")
    150 loaded_attributes = cls.from_json_file(config_file)

ValueError: Can't find 'adapter_config.json' at 'unsloth/llama-3-8b-bnb-4bit'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
Cell In[3], line 17
      5 load_in_4bit = True
      6 fourbit_models = [
      7     "unsloth/mistral-7b-bnb-4bit",
      8     "unsloth/mistral-7b-instruct-v0.2-bnb-4bit",
   (...)
     14     "unsloth/llama-3-8b-bnb-4bit", 
     15 ]
---> 17 model, tokenizer = FastLanguageModel.from_pretrained(
     18     pretrained_model_name_or_path = "/home/sr/projects/llama3/llama-3-8b-bnb-4bi",
     19     #model_name = "unsloth/llama-3-8b-bnb-4bit",
     20     max_seq_length = max_seq_length,
     21     dtype = dtype,
     22     load_in_4bit = load_in_4bit,
     23     local_files_only = True,
     24 )

File ~/anaconda3/envs/unsloth/lib/python3.10/site-packages/unsloth/models/loader.py:102, in FastLanguageModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, token, device_map, rope_scaling, fix_tokenizer, trust_remote_code, use_gradient_checkpointing, resize_model_vocab, *args, **kwargs)
    100     peft_config = PeftConfig.from_pretrained(model_name, token = token)
    101 except:
--> 102     raise RuntimeError(f"Unsloth: `{model_name}` is not a full model or a PEFT model.")
    104 # Check base model again for PEFT
    105 model_name = _get_model_name(peft_config.base_model_name_or_path, load_in_4bit)

RuntimeError: Unsloth: `unsloth/llama-3-8b-bnb-4bit` is not a full model or a PEFT model.```

qingxin113-1 avatar May 21 '24 02:05 qingxin113-1

Oh interesting someone did ask about this issue - working on a fix

danielhanchen avatar May 21 '24 20:05 danielhanchen

@qingxin113-1 Sorry but I am not able to understand. Just out of curiosity, can you please help me understand what is the issue you are facing? Have you downloaded a model offline and then trying to load in Unsloth?

ewre324 avatar May 25 '24 14:05 ewre324

The model has been loaded locally, so when the VPN is disconnected, it cannot be loaded from the local source anymore.

sujianwei1 avatar May 28 '24 09:05 sujianwei1

TimeoutError: timed out ... --> 102 raise RuntimeError(f"Unsloth: {model_name} is not a full model or a PEFT model.") 104 # Check base model again for PEFT 105 model_name = _get_model_name(peft_config.base_model_name_or_path, load_in_4bit)

RuntimeError: Unsloth: unsloth/llama-3-8b-Instruct-bnb-4bit is not a full model or a PEFT model.

sujianwei1 avatar May 28 '24 09:05 sujianwei1

@sujianwei1 Option 1: Run the code once with internet connectivity. This will download the model in HF cache and it will be there for fututre offline use.

Option 2: Update you given code by this

model, tokenizer = FastLanguageModel.from_pretrained(
    #pretrained_model_name_or_path = "/home/sr/projects/llama3/llama-3-8b-bnb-4bi",
    model_name = "/home/sr/projects/llama3/llama-3-8b-bnb-4bi",
    max_seq_length = max_seq_length,
    dtype = dtype,
    load_in_4bit = load_in_4bit,
    local_files_only = True,
)
)

Let me know if this works or not

ewre324 avatar May 28 '24 10:05 ewre324

local_files_only = True makes it work successfully

sujianwei1 avatar May 28 '24 10:05 sujianwei1

OHH! @erwe324 Thanks for that!! Oh wait maybe I should actually try except this lol

danielhanchen avatar May 28 '24 14:05 danielhanchen