Spaces:
Running
Running
| """ | |
| Example: How to Upload SAE Weights to Hugging Face | |
| This script shows how to upload your trained SAE weights to Hugging Face | |
| so they can be easily loaded in the demo app. | |
| """ | |
| from huggingface_hub import HfApi, create_repo | |
| import os | |
| api = HfApi() | |
| REPO_ID = "your-username/sae-weights" | |
| SAE_CHECKPOINT_PATH = "path/to/your/sae_l16.pt" | |
| try: | |
| create_repo(REPO_ID, repo_type="model", exist_ok=True) | |
| print(f"Created repository: {REPO_ID}") | |
| except Exception as e: | |
| print(f"Repository may already exist: {e}") | |
| api.upload_file( | |
| path_or_fileobj=SAE_CHECKPOINT_PATH, | |
| path_in_repo="sae_l16.pt", | |
| repo_id=REPO_ID, | |
| repo_type="model" | |
| ) | |
| print(f"Uploaded SAE weights to {REPO_ID}") | |
| print(f"Load in demo with:") | |
| print(f" Repository ID: {REPO_ID}") | |
| print(f" Filename: sae_l16.pt") | |
| print("\n" + "="*60) | |
| print("Example: Upload Multiple SAE Checkpoints") | |
| print("="*60) | |
| checkpoints = { | |
| "sae_layer_8.pt": "path/to/sae_l8.pt", | |
| "sae_layer_16.pt": "path/to/sae_l16.pt", | |
| "sae_layer_24.pt": "path/to/sae_l24.pt" | |
| } | |
| for filename, local_path in checkpoints.items(): | |
| if os.path.exists(local_path): | |
| api.upload_file( | |
| path_or_fileobj=local_path, | |
| path_in_repo=filename, | |
| repo_id=REPO_ID, | |
| repo_type="model" | |
| ) | |
| print(f"Uploaded {filename}") | |
| print("\n" + "="*60) | |
| print("Example: Upload Dataset to Hugging Face") | |
| print("="*60) | |
| from datasets import Dataset, DatasetDict | |
| import pandas as pd | |
| data = { | |
| "text": [ | |
| "Example text 1", | |
| "Example text 2", | |
| "Example text 3" | |
| ], | |
| "label": [0, 1, 0] | |
| } | |
| df = pd.DataFrame(data) | |
| dataset = Dataset.from_pandas(df) | |
| dataset_dict = DatasetDict({ | |
| "train": dataset | |
| }) | |
| DATASET_REPO_ID = "your-username/custom-dataset" | |
| dataset_dict.push_to_hub(DATASET_REPO_ID) | |
| print(f"Uploaded dataset to {DATASET_REPO_ID}") | |
| print("\n" + "="*60) | |
| print("All uploads complete!") | |
| print("="*60) | |
| print("\nNow in the demo app:") | |
| print("1. Select 'Hugging Face' as SAE source") | |
| print(f"2. Enter Repository ID: {REPO_ID}") | |
| print("3. Enter Filename: sae_l16.pt") | |
| print("4. Click 'Load from Hugging Face'") | |
| print("\nFor custom datasets:") | |
| print("1. Expand 'Advanced: Custom Dataset'") | |
| print(f"2. Enter Dataset Repository ID: {DATASET_REPO_ID}") | |
| print(f"3. Enter SAE Repository ID: {REPO_ID}") | |
| print("4. Click 'Load Custom Configuration'") | |