Jibbalit commited on
Commit
2239421
·
1 Parent(s): 057ef60

Use provided HF token explicitly for download and push

Browse files
Files changed (1) hide show
  1. wave_tank_surgeon.py +15 -4
wave_tank_surgeon.py CHANGED
@@ -607,16 +607,27 @@ def main():
607
  print(f"Training: {args.steps} steps, lr={args.lr}")
608
  print("=" * 70)
609
 
 
 
 
 
 
 
610
  # Load model and tokenizer
611
  print(f"Loading model: {args.model}...")
612
  from transformers import AutoModelForCausalLM, AutoTokenizer
613
 
614
- tokenizer = AutoTokenizer.from_pretrained(args.model, trust_remote_code=True)
 
 
 
 
615
  model = AutoModelForCausalLM.from_pretrained(
616
  args.model,
617
  torch_dtype=torch_dtype,
618
  device_map='auto' if torch.cuda.is_available() else None,
619
  trust_remote_code=True,
 
620
  )
621
 
622
  if device.type == 'cpu' or (device.type == 'cuda' and not hasattr(model, 'hf_device_map')):
@@ -794,11 +805,11 @@ def main():
794
  # Push to Hub if requested
795
  if args.push_to_hub:
796
  print(f"Pushing to HuggingFace Hub: {args.push_to_hub}...")
797
- model.push_to_hub(args.push_to_hub, private=args.private)
798
- tokenizer.push_to_hub(args.push_to_hub, private=args.private)
799
  # Also push surgery report
800
  from huggingface_hub import HfApi
801
- api = HfApi()
802
  api.upload_file(
803
  path_or_fileobj=os.path.join(output_dir, 'surgery_report.json'),
804
  path_in_repo='surgery_report.json',
 
607
  print(f"Training: {args.steps} steps, lr={args.lr}")
608
  print("=" * 70)
609
 
610
+ hf_token = (
611
+ os.environ.get('HF_TOKEN')
612
+ or os.environ.get('HUGGING_FACE_HUB_TOKEN')
613
+ or os.environ.get('HUGGINGFACEHUB_API_TOKEN')
614
+ )
615
+
616
  # Load model and tokenizer
617
  print(f"Loading model: {args.model}...")
618
  from transformers import AutoModelForCausalLM, AutoTokenizer
619
 
620
+ tokenizer = AutoTokenizer.from_pretrained(
621
+ args.model,
622
+ trust_remote_code=True,
623
+ token=hf_token,
624
+ )
625
  model = AutoModelForCausalLM.from_pretrained(
626
  args.model,
627
  torch_dtype=torch_dtype,
628
  device_map='auto' if torch.cuda.is_available() else None,
629
  trust_remote_code=True,
630
+ token=hf_token,
631
  )
632
 
633
  if device.type == 'cpu' or (device.type == 'cuda' and not hasattr(model, 'hf_device_map')):
 
805
  # Push to Hub if requested
806
  if args.push_to_hub:
807
  print(f"Pushing to HuggingFace Hub: {args.push_to_hub}...")
808
+ model.push_to_hub(args.push_to_hub, private=args.private, token=hf_token)
809
+ tokenizer.push_to_hub(args.push_to_hub, private=args.private, token=hf_token)
810
  # Also push surgery report
811
  from huggingface_hub import HfApi
812
+ api = HfApi(token=hf_token)
813
  api.upload_file(
814
  path_or_fileobj=os.path.join(output_dir, 'surgery_report.json'),
815
  path_in_repo='surgery_report.json',