Browse Source

Polish stdout

Aleksandr Borzunov 3 năm trước cách đây
mục cha
commit
4918c58cb6
3 tập tin đã thay đổi với 27 bổ sung33 xóa
  1. 2 2
      callback.py
  2. 23 29
      huggingface_auth.py
  3. 2 2
      run_aux_peer.py

+ 2 - 2
callback.py

@@ -68,9 +68,9 @@ class CollaborativeCallback(transformers.TrainerCallback):
                     loss=self.loss,
                     mini_steps=self.steps,
                 )
-                logger.info(f"Step {self.collaborative_optimizer.local_epoch}")
+                logger.info(f"Current epoch: {self.collaborative_optimizer.local_epoch}")
                 logger.info(f"Your current contribution: {self.total_samples_processed} samples")
-                logger.info(f"Performance: {samples_per_second} samples per second.")
+                logger.info(f"Performance: {samples_per_second} samples/sec")
                 if self.steps:
                     logger.info(f"Local loss: {self.loss / self.steps}")
 

+ 23 - 29
huggingface_auth.py

@@ -153,21 +153,17 @@ def authorize_with_huggingface() -> HuggingFaceAuthorizer:
 
         hf_user_access_token = os.getenv('HF_USER_ACCESS_TOKEN')
         if hf_user_access_token is None:
-            msg = [
-                "Copy a token from your Hugging Face tokens page at ",
-                colored("https://huggingface.co/settings/token", attrs=['bold']),
-                "and paste it.\n💡",
-                colored("Pro Tip:", attrs=['bold']),
-                "If you don't already have one, you can create a dedicated user access token. Go to "
-                "https://huggingface.co/settings/token and click on the `new token` button. ",
-                "You just need to give a ",
-                colored("'read'", attrs=['bold']),
-                "role to this access token." ,
-                "Don't forget to give an explicit name to this access token like",
-                colored(f"'{organization_name}-{model_name}-collaborative-training'", attrs=['bold'])
-                ]
-            print(*msg)
-            hf_user_access_token = getpass('HF user access token : ')
+            print(
+                "\nCopy a token from 🤗 Hugging Face settings page at "
+                f"{colored('https://huggingface.co/settings/token', attrs=['bold'])} "
+                "and paste it here.\n\n"
+                f"💡 {colored('Tip:', attrs=['bold'])} "
+                "If you don't already have one, you can create a dedicated user access token.\n"
+                f"Go to {colored('https://huggingface.co/settings/token', attrs=['bold'])}, "
+                f"click the {colored('New token', attrs=['bold'])} button, "
+                f"and choose the {colored('read', attrs=['bold'])} role.\n"
+            )
+            hf_user_access_token = getpass('🤗 Hugging Face user access token (characters will be hidden): ')
 
             authorizer = HuggingFaceAuthorizer(organization_name, model_name, hf_user_access_token)
 
@@ -175,23 +171,21 @@ def authorize_with_huggingface() -> HuggingFaceAuthorizer:
             authorizer.join_experiment()
 
             username = authorizer._local_access_token.username
-            print(f"🚀 You will contribute to the collaborative training under the username {username}.")
+            print(f"🚀 You will contribute to the collaborative training under the username {username}")
             return authorizer
         except InvalidCredentialsError:
             print('Invalid user access token, please try again')
         except NotInAllowlistError:
             print(
-                '😥 Authentication has failed. '
-                'This error may be due to the fact:\n',
-                "   1. your user access token is not valid. You can try to delete the previous token and"
-                " recreate one. Be careful, organization tokens can't be used to join a collaborative "
+                '\n😥 Authentication has failed.\n\n'
+                'This error may be due to the fact:\n'
+                "    1. Your user access token is not valid. You can try to delete the previous token and "
+                "recreate one. Be careful, organization tokens can't be used to join a collaborative "
                 "training.\n"
-                f"   2. you have not yet joined the {organization_name} organization. You can request to"
-                " join this organization by clicking on the 'request to join this org' button at "
-                f"https://huggingface.co/{organization_name}.\n",
-                f"   3. the {organization_name} organization doesn't exist at https://huggingface.co/{organization_name}.\n",
-                f"   4. no {organization_name}'s admin has created a collaborative training for the {organization_name}"
-                f"organization and the {model_name} model.",
-                )
-    
-
+                f"    2. You have not yet joined the {organization_name} organization. You can request to "
+                "join this organization by clicking on the 'request to join this org' button at "
+                f"https://huggingface.co/{organization_name}.\n"
+                f"    3. The {organization_name} organization doesn't exist at https://huggingface.co/{organization_name}.\n"
+                f"    4. No {organization_name}'s admin has created a collaborative training for the {organization_name} "
+                f"organization and the {model_name} model."
+            )

+ 2 - 2
run_aux_peer.py

@@ -64,7 +64,7 @@ class CheckpointHandler:
         torch.save(self.task.collaborative_optimizer.state_dict(), f"{self.local_path}/optimizer_state.pt")
         self.previous_timestamp = time.time()
         logger.info("Started uploading to Model Hub")
-        self.repo.push_to_hub(commit_message=f"Step {self.task.collaborative_optimizer.local_epoch}, loss {current_loss:.3f}")
+        self.repo.push_to_hub(commit_message=f"Epoch {self.task.collaborative_optimizer.local_epoch}, loss {current_loss:.3f}")
         logger.info("Finished uploading to Model Hub")
 
 
@@ -122,7 +122,7 @@ if __name__ == "__main__":
                     num_samples += item.samples_accumulated
                     sum_mini_steps += item.mini_steps
                 current_loss = sum_loss / sum_mini_steps
-                logger.info(f"Step #{current_step}\tloss = {current_loss:.5f}")
+                logger.info(f"Epoch #{current_step}\tloss = {current_loss:.5f}")
 
                 if peer_args.wandb_project is not None:
                     wandb.log(