Upload 2 files
Browse files- code/train.py +10 -1
code/train.py
CHANGED
|
@@ -32,12 +32,14 @@ logger = logging.getLogger(__name__)
|
|
| 32 |
def get_hf_token():
|
| 33 |
token = os.environ.get("HF_TOKEN")
|
| 34 |
if token:
|
|
|
|
| 35 |
logger.info("Loaded HF_TOKEN from environment.")
|
| 36 |
return token
|
| 37 |
if HAS_KAGGLE_SECRETS:
|
| 38 |
try:
|
| 39 |
token = UserSecretsClient().get_secret("HF_TOKEN")
|
| 40 |
if token:
|
|
|
|
| 41 |
os.environ["HF_TOKEN"] = token
|
| 42 |
logger.info("Loaded HF_TOKEN from kaggle_secrets.")
|
| 43 |
return token
|
|
@@ -127,7 +129,11 @@ class ShardPool:
|
|
| 127 |
self._refresh_file_list()
|
| 128 |
|
| 129 |
def _refresh_file_list(self):
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
self.available_files = [f for f in files if f.startswith("shards/hi_indiccorp_") and f.endswith(".bin")]
|
| 132 |
np.random.shuffle(self.available_files)
|
| 133 |
|
|
@@ -247,6 +253,9 @@ def main():
|
|
| 247 |
logger.info("Loading validation data...")
|
| 248 |
try:
|
| 249 |
val_files = [f for f in api.list_repo_files(repo_id="ViuAI/ViuCorp", repo_type="dataset", token=token) if f.startswith("val_shards/")]
|
|
|
|
|
|
|
|
|
|
| 250 |
if val_files:
|
| 251 |
val_p = hf_hub_download(repo_id="ViuAI/ViuCorp", repo_type="dataset", filename=val_files[0], local_dir=work_dir, token=token)
|
| 252 |
dtype = np.uint16 if vocab_size <= 65535 else np.uint32
|
|
|
|
| 32 |
def get_hf_token():
|
| 33 |
token = os.environ.get("HF_TOKEN")
|
| 34 |
if token:
|
| 35 |
+
token = token.strip()
|
| 36 |
logger.info("Loaded HF_TOKEN from environment.")
|
| 37 |
return token
|
| 38 |
if HAS_KAGGLE_SECRETS:
|
| 39 |
try:
|
| 40 |
token = UserSecretsClient().get_secret("HF_TOKEN")
|
| 41 |
if token:
|
| 42 |
+
token = token.strip()
|
| 43 |
os.environ["HF_TOKEN"] = token
|
| 44 |
logger.info("Loaded HF_TOKEN from kaggle_secrets.")
|
| 45 |
return token
|
|
|
|
| 129 |
self._refresh_file_list()
|
| 130 |
|
| 131 |
def _refresh_file_list(self):
|
| 132 |
+
try:
|
| 133 |
+
files = self.api.list_repo_files(repo_id=self.repo_id, repo_type="dataset", token=self.token)
|
| 134 |
+
except Exception as e:
|
| 135 |
+
logger.warning(f"Failed to list dataset repo {self.repo_id}, trying as model repo. Error: {e}")
|
| 136 |
+
files = self.api.list_repo_files(repo_id=self.repo_id, repo_type="model", token=self.token)
|
| 137 |
self.available_files = [f for f in files if f.startswith("shards/hi_indiccorp_") and f.endswith(".bin")]
|
| 138 |
np.random.shuffle(self.available_files)
|
| 139 |
|
|
|
|
| 253 |
logger.info("Loading validation data...")
|
| 254 |
try:
|
| 255 |
val_files = [f for f in api.list_repo_files(repo_id="ViuAI/ViuCorp", repo_type="dataset", token=token) if f.startswith("val_shards/")]
|
| 256 |
+
except Exception:
|
| 257 |
+
val_files = [f for f in api.list_repo_files(repo_id="ViuAI/ViuCorp", repo_type="model", token=token) if f.startswith("val_shards/")]
|
| 258 |
+
try:
|
| 259 |
if val_files:
|
| 260 |
val_p = hf_hub_download(repo_id="ViuAI/ViuCorp", repo_type="dataset", filename=val_files[0], local_dir=work_dir, token=token)
|
| 261 |
dtype = np.uint16 if vocab_size <= 65535 else np.uint32
|