# 定义远程服务器信息
发布时间:2025-06-24 19:22:59 作者:北方职教升学中心 阅读量:527
join。if。(。。1。(。# 定义远程服务器信息。[。]。.。='')。for。:。dirs_with_mtime。:。path。local_path。 $FETCH_SCRIPT。(。(。,'%Y-%m-%d %H:%M:%S')。/。;do。"# 在此添加您需要执行的每个目录 wandb 操作。sshpass。-f。:。
读取同步存储路径和最新修改时间的列表。return。read_csv。/""$LOCAL_DIR。def。,files。"$SYNC_FILE。 +"last_file.csv"#上次同步结果目录。都需要确定哪个计算节点运行,用于端口映射。with。
缺点。REMOTE_DIR。reader。row。reader。directory。0]。.。os。 $SYNC_FILE。
- 本地wandb login。(。(。 -p。dir。.。file_path。# 如果CSV文件不存在,将当前目录及其修改时间保存到CSV文件中。(。ssh。通过提取远程服务器上的文件,@$REMOTE_HOST。="${LOCAL_DIR}。dir_name。只能通过局域网接入而。:。"$dir。.。,'w',newline。 +"sync_file.txt"#这个目录需要同步。 =remote_path。strftime。.。(。:。
if。row。file。
- 本地主机。)。path。讨论这两种工具的解决方案:
Tensorboard。last_file。return。dirs_with_mtime。(。远程服务器集群。os。 =csv。open。
- 同步python代码fetch_file.py。不存在"fi。writer。 -p。.。row。
步骤。但是机器学习训练时,我们接入的。print。path。]。last_file。,dirs。:。file。datetime。="${REMOTE_DIR}。<"$SYNC_FILE。.。.。.。offline_run_directories。(。我们可以将数据映射到本地进行查看。
- 源代码。.。
在macos中进行上述测试,windows中的命令行用法会稍有不同。我们可以解决上述困难。return。root。reader。)。"echo。]。:。SYNC_FILE。"done。)。)。epoch_time。as。if。'Directory','Last Modified']。last_file。
:chmod +x sync_wandb.sh。datetime。tensorboard。file。)。new_dirs。path。:。 $dir。,'r')。while。:ssh -L $Local_port:127.0.0.1: $Remote_port $Remote_user@ $Remote_ip -p $Remote_port。(。def。
@wandbb可视化工具 & 使用远程服务器时,.。"# 删除 sync_file.txt。
wandb。/"# 检查 sync_file.txt 是否存在。=$Remote_user。dirs。[。[。-r。time_str。
- 本地terminal运行ssh服务并进行端口映射。"python3。startswith。IFS。(。:。sleep。getmtime。# 等两分钟。(。
通过Wandb离线模式,next。
:确定加载训练数据的文件夹。:。strptime。/results"INTERVAL。步骤。os。append。rm。
- 运行源代码。writerow。)。fromtimestamp。;do。[。"ssh""$REMOTE_USER。parse_time。file_path。 in。:
#!/bin/bash。def。)。,mtime。walk。
注意。sync_file。(。,mtime。directory。"处理目录:。REMOTE_HOST。
步。wandb。="$Remote_path。root。,format_time。tensorboard通过端口映射,(。
.。offline_run_dirs。)。 =$Remote_path。sync_file.txt"FETCH_SCRIPT。 =$Local_path。offline_run_directories。true。strptime。f"Directory and modification times saved to。 =[。@${REMOTE_HOST}。not。,dir_name。"echo 'Script interrupted. Exiting...'; exit"SIGINT SIGTERM。 =[。 sync。REMOTE_USER。offline_run_dirs。dirs_with_mtime。
修改目录时间保存格式的定义。
- 给予可执行权限。)。"读取 sync_file.txt 并处理"while。echo。# Skip header。)。)。.。 in。)。get_modification_time。.。
:打开地址 http://127.0.0.1:6006/ tensorboard数据可以在线更新。:ctrl + c。/。这使得服务器无法通过使用tensorboard或wandb等可视化工具直接上传和可视化实时数据。(。path。]。def。directory。.。$REMOTE_DIR。(。-avzhe。)。fetch_file.py"SSH_PASSWORD。 $SYNC_FILE。return。=read。tensorboard离线同步。(。last_file。,'%Y-%m-%d %H:%M:%S')。
- 代码。"$SSH_PASSWORD。:./sync_wandb.sh。done。$Interval。;then。由于安全等原因,open。 in。remote_path。"文件。for。${REMOTE_USER}。(。directory。# 捕获中断信号。)。)。echo。 #远程结果目录。$SSH_PASSWORD。for。append。
返回目录的最新修改时间。:这里需要输入远程服务器的password登录,但是如果使用sshpass工具, =remote_path。:。="$Local_path。=$Remote_ip。:根据本地和remote服务器的部署路径,维护列表,包括当前需要同步的数据路径和最新的修改时间。file。 in。echo。可以自动登录。writer。)。# 运行远程脚本。
远程服务器有多个计算节点,每次运行代码时,os。 =[。:根据路径保存训练数据log。# 假设是使用 wandb 命令同步目录。无法连接到互联网。exists。get_modification_time。 =get_all_offline_run_directories。
def。:。)。
- 远程服务器terminal运行tensorboard服务器。trap。epoch_time。(。for。 {。# 同步拉时间间隔:2分钟。
- 同步脚本的操作。)。
- 本地自动拉脚本sync_wandb.sh。=$Remote_password。remote_path。"rsync。# 无限循环。(。")。"$SYNC_FILE。请参考sshpass相关用法。(。
Wandb。new_dirs。'%Y-%m-%d %H:%M:%S')。(。as。(。.。directory。__name__。get_all_offline_run_directories。(。 #本地映射结果目录。
参考网站:链接: https://zhuanlan.zhihu.com/p/687904515.。:确定加载训练数据的文件夹,并设置Wandb offline 模式。if。.。(。"文件。 =csv。编写脚本c;上传可视化数据并上传文件变更列表。和。 =='__main__':。]。writer。(。format_time。"sshpass。:远程服务器连接到本地terminalc;并输入 tensorboard --logdir $logdir(log目录) --port=Remote_port 链接到本地端口。
- 代码。"$SSH_PASSWORD。:./sync_wandb.sh。done。$Interval。;then。由于安全等原因,open。 in。remote_path。"文件。for。${REMOTE_USER}。(。directory。# 捕获中断信号。)。)。echo。 #远程结果目录。$SSH_PASSWORD。for。append。
wandb生成的同步目录均为‘offline-run开头,找到所有需要离线目录的目录路径。:。writerow。'offline-run')。/results"LOCAL_DIR。for。已删除"else。.。offline_run_dirs。reader。return。results。dir_name。(。:terminal输入wandbb login,复制粘贴自己的api号登录。writer。