Codex commited on
Commit
b7eb7c7
·
1 Parent(s): 63136ea

Debug: add test_token function to verify HF secret injection

Browse files
Files changed (1) hide show
  1. tune.py +27 -2
tune.py CHANGED
@@ -180,8 +180,8 @@ def train_lora(hf_token: str | None = None, repo_id: str | None = None):
180
 
181
  # Push to Hugging Face Hub if token is available
182
  if hf_token:
183
- token_preview = hf_token[:6] + "..." + hf_token[-4:]
184
- print(f"HF_TOKEN loaded (masked): {token_preview}")
185
  login(token=hf_token)
186
  print(
187
  f"Pushing fine-tuned adapter to Hugging Face Hub repository: {repo_id}..."
@@ -191,3 +191,28 @@ def train_lora(hf_token: str | None = None, repo_id: str | None = None):
191
  print("Pushed successfully!")
192
  else:
193
  print("HF_TOKEN not set or provided. Skipping publishing step.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
 
181
  # Push to Hugging Face Hub if token is available
182
  if hf_token:
183
+ print(f"[DEBUG] hf_token value: '{hf_token}'")
184
+ print(f"[DEBUG] HF-related env vars: { {k: v for k, v in os.environ.items() if 'HF' in k or 'HUGGING' in k} }")
185
  login(token=hf_token)
186
  print(
187
  f"Pushing fine-tuned adapter to Hugging Face Hub repository: {repo_id}..."
 
191
  print("Pushed successfully!")
192
  else:
193
  print("HF_TOKEN not set or provided. Skipping publishing step.")
194
+
195
+
196
+ # Lightweight function to verify HF token injection without running training
197
+ @app.function(
198
+ image=image,
199
+ secrets=[modal.Secret.from_name("huggingface-secret")],
200
+ )
201
+ def test_token():
202
+ """Prints the HF_TOKEN value from the container environment for debugging."""
203
+ from huggingface_hub import whoami
204
+
205
+ token = os.environ.get("HF_TOKEN")
206
+ print(f"HF_TOKEN raw value: '{token}'")
207
+ hf_vars = {k: v for k, v in os.environ.items() if "HF" in k or "HUGGING" in k}
208
+ print(f"All HF-related env vars: {hf_vars}")
209
+ if token:
210
+ info = whoami(token=token)
211
+ print(f"Authenticated as: {info['name']}")
212
+ else:
213
+ print("No HF_TOKEN found in environment.")
214
+
215
+
216
+ @app.local_entrypoint()
217
+ def main():
218
+ test_token.remote()