Repository: pytorch/torchtune

Issue:
Unclear Error Message for GatedRepoError When --hf-token is Provided
## Description 
The error message for GatedRepoError asks the user to provide the --hf-token, even when the token is already passed via the command-line option. This is confusing for users who have already provided the token.

## _Expected Behavior_: 
If the --hf-token argument is passed, the error message should not request it again and should focus on other potential issues (e.g., access rights or incorrect token).

## _Current Behavior_: 
The error message currently states:

```txt
"Please ensure you have access to the repository and have provided the proper Hugging Face API token using the option --hf-token or by running huggingface-cli login. You can find your token by visiting https://huggingface.co/settings/tokens"
This should not appear if the --hf-token has already been provided.
```

## Steps to Reproduce:

1. Pass a valid --hf-token when running the command.
2. Encounter the GatedRepoError.
3. Observe the message requesting the token, despite it being passed.
![image](https://github.com/user-attachments/assets/af40d048-8a92-4fbe-b238-a24e827288f8)

## **Suggested Fix**: 
The error message should only suggest providing the token if it wasn’t passed through the command-line argument.





Discussion:

Patch:
diff --git a/torchtune/_cli/download.py b/torchtune/_cli/download.py
index b35b81cca0..82b4935c01 100644
--- a/torchtune/_cli/download.py
+++ b/torchtune/_cli/download.py
@@ -131,12 +131,18 @@ def _download_cmd(self, args: argparse.Namespace) -> None:
                 token=args.hf_token,
             )
         except GatedRepoError:
-            self._parser.error(
-                "It looks like you are trying to access a gated repository. Please ensure you "
-                "have access to the repository and have provided the proper Hugging Face API token "
-                "using the option `--hf-token` or by running `huggingface-cli login`."
-                "You can find your token by visiting https://huggingface.co/settings/tokens"
-            )
+            if args.hf_token:
+                self._parser.error(
+                    "It looks like you are trying to access a gated repository. Please ensure you "
+                    "have access to the repository."
+                )
+            else:
+                self._parser.error(
+                    "It looks like you are trying to access a gated repository. Please ensure you "
+                    "have access to the repository and have provided the proper Hugging Face API token "
+                    "using the option `--hf-token` or by running `huggingface-cli login`."
+                    "You can find your token by visiting https://huggingface.co/settings/tokens"
+                )
         except RepositoryNotFoundError:
             self._parser.error(
                 f"Repository '{args.repo_id}' not found on the Hugging Face Hub."


Test patch:
diff --git a/tests/torchtune/_cli/test_download.py b/tests/torchtune/_cli/test_download.py
index 5dbd695226..8a6d6ba0ab 100644
--- a/tests/torchtune/_cli/test_download.py
+++ b/tests/torchtune/_cli/test_download.py
@@ -65,3 +65,44 @@ def test_download_calls_snapshot(self, capsys, monkeypatch, snapshot_download):
 
         # Make sure it was called twice
         assert snapshot_download.call_count == 3
+
+    # GatedRepoError without --hf-token (expect prompt for token)
+    def test_gated_repo_error_no_token(self, capsys, monkeypatch, snapshot_download):
+        model = "meta-llama/Llama-2-7b"
+        testargs = f"tune download {model}".split()
+        monkeypatch.setattr(sys, "argv", testargs)
+
+        # Expect GatedRepoError without --hf-token provided
+        with pytest.raises(SystemExit, match="2"):
+            runpy.run_path(TUNE_PATH, run_name="__main__")
+
+        out_err = capsys.readouterr()
+        # Check that error message prompts for --hf-token
+        assert (
+            "It looks like you are trying to access a gated repository." in out_err.err
+        )
+        assert (
+            "Please ensure you have access to the repository and have provided the proper Hugging Face API token"
+            in out_err.err
+        )
+
+    # GatedRepoError with --hf-token (should not ask for token)
+    def test_gated_repo_error_with_token(self, capsys, monkeypatch, snapshot_download):
+        model = "meta-llama/Llama-2-7b"
+        testargs = f"tune download {model} --hf-token valid_token".split()
+        monkeypatch.setattr(sys, "argv", testargs)
+
+        # Expect GatedRepoError with --hf-token provided
+        with pytest.raises(SystemExit, match="2"):
+            runpy.run_path(TUNE_PATH, run_name="__main__")
+
+        out_err = capsys.readouterr()
+        # Check that error message does not prompt for --hf-token again
+        assert (
+            "It looks like you are trying to access a gated repository." in out_err.err
+        )
+        assert "Please ensure you have access to the repository." in out_err.err
+        assert (
+            "Please ensure you have access to the repository and have provided the proper Hugging Face API token"
+            not in out_err.err
+        )