Code Monkey home page Code Monkey logo

fitlog's Introduction

fitlog

Pypi

fitlog = fast + git + log, 是一款用于辅助用户记录日志和管理代码的工具,主要支持 Linux 和 macOS,也支持在 Windows 的 Git Bash 中使用。

fitlog中文文档

file structure

|-setup.py
|-docs
|-fitlog
|  |--- init
|  |--- fastlog
|  |--- fastgit
|  |--- server
|-tests
  

update schedule

filog 是我们实验室内部使用的一款工具,大部分功能口口相传,文档和教程还没有特别全。感谢大家的尝试使用,遇到问题可以在 Issues 处提出。

一些使用说明

  1. 如果在debug阶段,不希望fitlog发生任何作用,那么直接在入口代码处(import fitlog的下一行)加入fitlog.debug()就可以让所有的fitlog调用不起任何作用,debug结束再注释掉这一行就可以了。 如果希望在某一段代码不要记录,可以在这段代码之前fitlog.debug(flag=True), 跑出这段代码之后fitlog.debug(flag=True)即可恢复
  2. fitlog默认只有在产生了第一个metric或loss的时候才会创建log文件夹,防止因为其它bug还没运行到model就崩溃产生大量无意义的log。
  3. 如果使用了分布式训练,一般只需要主进程记录fitlog就好。这个时候可以通过将非主进程的fitlog设置fitlog.debug()
    import torch
    import fitlog
    
    if torch.distributed.get_rank()>0:
        fitlog.debug()
  4. 不要通过多进程使用fitlog,即multiprocessing模块。
  5. fitlog.commit()只需要在某个python文件调用就可以了,一般就在入口python文件即可。
  6. 传入到fitlog的各种参数、metric的名称,请 避免特殊符号(例如$%!#@空格),请只使用_与各种字母的组合 ,因为特殊符号可能导致网页端显示不正常。
  7. 在命令行中通过fitlog log logs打开网页的时候,如果出现了网页无法访问的情况,首先检查一下ip地址是否正确,例如如果是在服务器上启动的服务,在电脑这端应该用http://服务器的ip:5000 来访问,如果是在本地电脑启动的,可以尝试通过http://0.0.0.0:5000http://127.0.0.1:5000http://localhost:5000 访问。如果以上仍然不能访问,可以通过ctrl+c关闭fitlog服务,然后通过命令fitlog log logs --ip 127.0.0.1启动再试一下能不能访问。

Developing Features(2020.09.13)

以下为正在开发中的功能,API 可能发生变化。

为函数 fitlog.finish 增加了可选参数 send_to_bot,传入一个字符串,为飞书机器人的 webhook 地址。 使用这个参数可以让用户在训练完成时收到通知。

例如:设定 status 为 1, send_to_bot 为 webhook 的地址,可让飞书机器人发布训练发生错误的讯息。(status默认值为0,表示实验成功结束)

fitlog.finish(status=1,
	send_to_bot="https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxx")      

添加飞书机器人的方法参考群聊机器人

New Features(2020.06.11)

以下的功能都没有经过实战使用检验,可能有bug。

1. 支持一些复杂筛选条件

现在支持在Table那个页面的search框中输入复杂搜索逻辑进行筛选,例如下面log

before_search

想要搜索2020年06月11号15点到2020年06月11号16点之间,并且hidden_size大于60的log, 可以通过下面的语法输入到search框中

${'id':'log_20200611_150000<=&&<=log_20200611_160000', 'hyper-hidden_size':'>60'}$

使用效果如下(只显示满足条件的log了)

after_search

其中开头结尾的$是特殊标记符号,申明这是特殊搜索,否则fitlog会只进行常规字符串匹配搜索。由于search框一旦有文字就会触发搜索,所以建议在其他地方把文本编辑好,直接复制到search框中。支持的search语法规则如下

  1. 支持使用list表达或的关系。比如{"hyper-lr":[0.3, 0.1]}表示等于0.3或者0.1都会显示在前端。
  2. 支持通过>,<,<=,>=表示范围.{"hyper-lr":"<0.3", "hyper-dropout":">0.5"}表示lr小于0.3且dropout大于0.5的才保留。 大于小于符号可以在条件的最右边或者最左边,即"<0.5"或"0.5>"是等价的。
  3. 支持不等式操作,例如{'hyper-dropout':"!=0.4"}则为dropout不是0.4的才会保留
  4. 使用大于小于的场景,支持通过&&表达并且如{"hyper-lr":"0.1<&&<0.3"},表示lr需要大于0.1但小于0.3。
  5. 不同column之间默认是and的关系比如{"hyper-lr": 0.1, "hyper-dropout":0.3}表示lr和dropout同时为0.1和0.3的log; 如果需要使得不同column之间为或的关系,可以通过在filter_condition中加入一个特殊的字段and_filters, 以下的条件表示是不同filter为或的关系{"and_filters":0, "hyper-lr": 0.1, "hyper-dropout":0.3}, 请通过0或1表示and_filters。 申明某个column时,它名称是从最top的header一路到最底层的header,通过-连接。例如hyper下面的hidden_size, 搜索的时候条件应该写为hyper-hidden_size。

2.支持多条log的metric收敛曲线对比

操作如下图所示,先选择需要对比的log(默认只能选择10条),然后点击右上角红色框处

compare_metric

然后会弹出选择需要对比的metric,选好需要对比的metric后点击确认跳转,跳转后界面为

compare_metric_trend

我十分垃圾的js代码能力坚定地告诉我:你们一定不可能需要对比loss曲线的,所以我就没有必要再做loss对比了🐶。

fitlog's People

Contributors

foreverfancy avatar pryest avatar willqvq avatar yhcc avatar ztxtech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fitlog's Issues

error when not employing the commit API

Hello, thanks for providing this wonderful tool.

When I use the tutorial codes in https://fitlog.readthedocs.io/zh/latest/user/quickstart.html and comment out the commit function, it goes wrong.

import fitlog
import random

fitlog.commit(__file__)  # auto commit your codes
fitlog.add_hyper_in_file(__file__)  # record your hyperparameters
######hyper
rand_seed = 12
######hyper
random.seed(rand_seed)
best_acc, best_step, step = 0, 0, 0

for i in range(200):
    step += 1
    if step % 20 == 0:
        loss = random.random()
        acc = random.random()
        fitlog.add_loss(loss, name="Loss", step=step)
        fitlog.add_metric(acc, name="Acc", step=step)
    if step % 100 == 0:
        test_acc = random.random()
        if test_acc > best_acc:
            best_acc = test_acc
            best_step = step
fitlog.add_best_metric({"Test": {"Acc": best_acc, "Step": best_step}})
fitlog.finish()  # finish the logging

Error information is as below,
image

Is it necessary to use the COMMIT API?

commit多个文件 & 与git混合使用

您好,我在使用fitlog中产生了一些疑问,烦请解答:

  1. 文档的例子是针对一个main.py进行commit的,如果我在实验中对几个文件都进行了修改,是否需要对所有修改的文件(或者说,所有我希望fitlog记录修改的文件)都进行fitlog.commit呢?
  2. fitlog如何和普通的git混合使用呢?我能或者有需要额外使用git进行add、commit这样的操作吗?还是说我只需要用fitlog进行commit就可以了?

谢谢!

如何查看fitlog下自动commit的代码变动

工具非常赞,提高了我的调参效率
想请问是否可以直接在网页上查看fitlog.commit的代码版本变动?如果目前工具不支持的话,有什么方案可以推荐吗?

fitlog revert 无法正确回退代码(版本:0.5.8)

您好:
我在代码起始位置加入fitlog.commit(file)后,按照fitlog revert xxx的方式回退代码,提升 Your code is reverted to /data/yubowen/experiments/NA_revert,但是在NA_revert文件夹中并没有代码,请问是什么问题呢?

能否选择直接使用.git做管理

是否可以有个选项直接使用.git做版本管理,不用.fitlog,这样更加简单一些,我也可以将logs和.fitconfig这些文件一起添加到git上去,如果放在.fitlog中不能提交到git上去,后面如果丢失,实验记录就丢了

同时跑两个训练脚本,刷新页面hyper会丢失项目

您好,

你们的项目正是我现在需要的日志管理文件,我刚开始使用,非常便利美观。

为了节省时间,通常分开跑不同参数的训练脚本,在同时运行的两个脚本中我调用了figlog,分别创造了两个文件夹(对应前端的两行),我发现刷新浏览器页面之后,hyper会变得奇怪丢失了一些项目,尝试在上方的列选项中重新勾选,发现也不见了一些项目。
目前的解决方法是,使用你们页面上的刷新而不是浏览器的刷新,并且无法对metric使用对比按钮。

是否是我操作错误?
期待你们以后的更新~

argparse结合fitlog的bug

你好,最近我想使用argparse模块和fitlog来进行调参实验,但是发现log日志中hyper.log内容显示的不对。

`
parser = argparse.ArgumentParser(description='Hyper Parameters For Traning')
parser.add_argument('-city', type=str, default='lishui', help='select dataset')
parser.add_argument('-nrnn', type=int, default=128, help='Hidden Dimension')
parser.add_argument('-nmlp', type=int, default=128, help='number of hidden size of MLP')
# parser.add_argument('-nlayers', type=int, default=1, help='Number of layers for RNN')

parser.add_argument('-epoch', type=int, default=1000, help='training epoch')
parser.add_argument('-batch', type=int, default=1024, help='Batch Size')
parser.add_argument('-lr', type=float, default=0.001, help='learning rate')

opt = parser.parse_args()
print(opt)

rand_seed = 123

patience = 50
######hyper
city = opt.city
hidden_size_rnn = opt.nrnn
hidden_size_mlp = opt.nmlp
batch_size = opt.batch
lr = opt.lr
max_epoch = opt.epoch
dropouts = None
######hyper`

例如上面代码所示,我通过命令行传入参数,并通过argparse解析传给主程序,并用fitlog的hyper parameter方式记录超参数。
结果在hyper.log中的内容为:
{"hyper": {"city": "opt.city", "hidden_size_rnn": "opt.nrnn", "hidden_size_mlp": "opt.nmlp", "batch_size": "opt.batch", "lr": "opt.lr", "max_epoch": "opt.epoch", "dropouts": "None"}}

fitlog只是简单把 '='前后的内容变成key和value,而没有解析出具体的值

在已存在的git仓库内部, 执行fitlog init 会报错

在已存在的git仓库内部, 执行fitlog init 会报错。提示如下:

`$ fitlog init
Traceback (most recent call last):
File "/Users/zhou/miniconda3/lib/python3.7/shutil.py", line 566, in move
os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/zhou/example/.fitlog' -> '/Users/zhou/example/.git'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/zhou/miniconda3/bin/fitlog", line 8, in
sys.exit(main_cmd())
File "/Users/zhou/miniconda3/lib/python3.7/site-packages/fitlog/fastcmd/init.py", line 49, in main_cmd
cmd_mapcmd
File "/Users/zhou/miniconda3/lib/python3.7/site-packages/fitlog/fastcmd/init_cmd.py", line 26, in init_cmd
committer.init_project(name, hide=args["--hide"], git=not args["--no-git"])
File "/Users/zhou/miniconda3/lib/python3.7/site-packages/fitlog/fastgit/committer.py", line 496, in init_project
self._switch_to_fast_git(pj_path)
File "/Users/zhou/miniconda3/lib/python3.7/site-packages/fitlog/fastgit/committer.py", line 167, in _switch_to_fast_git
shutil.move(fitlog_path, git_path)
File "/Users/zhou/miniconda3/lib/python3.7/shutil.py", line 580, in move
copy_function(src, real_dst)
File "/Users/zhou/miniconda3/lib/python3.7/shutil.py", line 266, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/Users/zhou/miniconda3/lib/python3.7/shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/zhou/example/.fitlog'`

希望能修复。十分感谢!

不使用addbestmetric,metric无法使用compare对比功能

fitlog.add_metric({"dev": {"Acc": acc}}, step=step)
如果只有这一行,则不能用compare对比两次实验的acc曲线,会显示No overlapped metric to compare.

必须是下面的
fitlog.add_metric({"dev": {"Acc": acc}}, step=step)
fitlog.add_best_metric({"dev":{"Acc":best_acc}})
才能有对比界面

是否可以跑实验的时候实时看loss

我有时看看如果不收敛就暂停一半就不跑了,但是我也需要记录log。
在网页端是否可以显示实时的loss变化曲线然后每隔多少秒自己刷新一次

是否支持自定义logging的级别?

您好,我看到源码中是在create_log_files()里定义了logging的级别,请问是否支持用户再次自定义这一级别呢?因为我不太希望在训练过程中出现很多行loss,因为tqdm已经可以满足这一需求。
谢谢!

无法打开网页

您好,我用fitlog log logs命令后没有网页显示,没有任何响应,输入localhost:5000后也一样。
参考issue中的方法用fitlog log logs/ --ip 127.0.0.1也不行。
重新安装beta版本也不行,一样没有显示。
图片

请问是什么原因?
我的环境是win10,python3.7

不能在浏览器显示?

您好,我在服务器上运行fitlog log logs后,
显示:
图片
之后浏览器输入http:192.168.1.124(服务器的IP):5000,显示拒绝连接

fitlog==0.3.2
服务器上安装是通过pip install fitlog进行安装的

之后感觉可能是版本太低,因此把就下载了source code,但是下载完后,我应该怎么去安装?
python setup.py
显示:
图片
后面的命令选项我应该填什么?
非常感谢您的回复!!!

RuntimeError: It seems like you are not running under a folder governed by fitlog.

Reach the root or home.
Can not find the config file.
Traceback (most recent call last):
File "train_presum.py", line 22, in
fitlog.commit('file')
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/fitlog-0.9.13-py3.8.egg/fitlog/init.py", line 95, in commit
_logger.commit(file, fit_msg)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/fitlog-0.9.13-py3.8.egg/fitlog/fastlog/logger.py", line 32, in wrapper
return func(*args, **kwargs)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/fitlog-0.9.13-py3.8.egg/fitlog/fastlog/logger.py", line 142, in commit
raise RuntimeError("It seems like you are not running under a folder governed by fitlog.\n" + msg['msg'])
RuntimeError: It seems like you are not running under a folder governed by fitlog.
Error: Config file is not found

wsl环境下报错

环境:win10 wsl ubuntu20.4 python3.7
fitlog init报权限问题,再执行一次提示成功
Traceback (most recent call last):
File "/mnt/d/Ubuntu/miniconda3/envs/test/bin/fitlog", line 8, in
sys.exit(main_cmd())
File "/mnt/d/Ubuntu/miniconda3/envs/test/lib/python3.7/site-packages/fitlog/fastcmd/init.py", line 49, in main_cmd
cmd_mapcmd
File "/mnt/d/Ubuntu/miniconda3/envs/test/lib/python3.7/site-packages/fitlog/fastcmd/init_cmd.py", line 26, in init_cmd
committer.init_project(name, hide=args["--hide"], git=not args["--no-git"])
File "/mnt/d/Ubuntu/miniconda3/envs/test/lib/python3.7/site-packages/fitlog/fastgit/committer.py", line 504, in init_project
shutil.copytree(os.path.join(tools_path, "logs"), os.path.join(pj_path, "logs"))
File "/mnt/d/Ubuntu/miniconda3/envs/test/lib/python3.7/shutil.py", line 368, in copytree
raise Error(errors)
shutil.Error: [('/mnt/d/Ubuntu/miniconda3/envs/test/lib/python3.7/site-packages/fitlog/fastgit/normal/logs', '/mnt/d/Github/extest/logs', "[Errno 13] Permission denied: '/mnt/d/Github/extest/logs'")]

save等一系列按键消失

查看完一组实验的曲线再返回主界面。 包括save在内的一系列按钮不见了。同时delete和erase按键也不起任何作用

请问如何将for循环和fitlog结合起来

比如我现在有个超参数alpha想从[1, 2...,10]中搜索,我写了一个for循环给我的算法传参数
for alpha in range(1, 11):
fitlog.add_hyper(alpha, 'alpha')
train(..., alpha)
`
在web页面里我发现下一个循环的数值会替换上一次的,没有办法得到10个值的结果。

是否支持多线程同时记录几个训练过程?

我的程序是多线程的,请问

我可以同时记录几个训练过程吗?
内部有锁吗?我可以在不同的线程log吗?

(PS:关键部分释放了gil所以没有性能问题,因为内存不够所以我想不同超参数的训练可以共享内存,多线程共享内存比较方便。)

可以自动搜索参数吗

比如在config里指定dropout = [0.1, 0.2, 0.3]
在代码里使用dropout = fitlog.config['dropout']
然后执行代码,自动执行三次试验,无需手动写循环,或者每次手动改变参数

多个log的曲线显示

目前只能显示单个log的不同metric,实际上往往需要显示同一metric在不同log下对比,请问如何操作?

Some error happens when initialize table.

你好,首先感谢fitlog。

今天我在使用fitlog的时候,发现了一个问题,可能是当我的实验记录条数(401条)过多,在打开网页的时候,会弹窗报错Some error happens when initialize table。
系统:win10,fitlog版本已经更新到最新。
请问应该如何解决这一问题?
期待您的回复。

fit_msg、git_msg和memo的edit无法保存

您好:
网页界面上对fit_msg、git_msg和memo进行edit后提示update successfully,但是刷新网页后还是edit之前的状态,有什么特殊操作需要进行么?

fitlog可以在windows下使用吗

我在windows下的anaconda 中安装了fitlog。
fitlog init example初始化时报错
错误信息:
'cp' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

请问是否支持python 3.5版本?

我尝试在服务器上安装fitlog, 但出现如下错误:

(venv-torch) zhy@node27:~$ pip install git+https://gitee.com/fastnlp/fitlog
Collecting git+https://gitee.com/fastnlp/fitlog
Cloning https://gitee.com/fastnlp/fitlog to /tmp/pip-req-build-gdyvazpp
Running command git clone -q https://gitee.com/fastnlp/fitlog /tmp/pip-req-build-gdyvazpp
ERROR: Package 'fitlog' requires a different Python: 3.5.2 not in '>=3.6'
WARNING: You are using pip version 19.3.1; however, version 20.3.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

增加lr可视化的功能

目前的可视化只有loss和metric能否添加上lr的可视化,这样可以清晰的记录lr schedule

[feature request] 多个project的实验记录之间合并

经常遇到很多个人用同一份code的不同branch在不同的机器上同时进行不同实验的情况,fitlog有没有打算加入合并多个project实验结果的功能?这样可以把大家的log合并在一起观察结果。

一个小bug

首先感谢作者,fitlig真的很好用,下面是我在使用中遇到的一个小bug。
当我使用argsparse传入列表参数时:
parser.add_argument("--hidden_dim",type=int,nargs='+')
此时type(args.hidden_dim)是list,但是执行fitlog.add_hyper(args)后,type(args.hidden_dim)为str,如果此时将次参数传入模型会造成错误。虽然这个bug可以规避,但是感觉也算是个小问题。

需要几个fitlog.commit(__file__)?

1.是否只要入口函数(比如main.py)里有一个fitlog.commit(file)就可以了,其他文件中不需要?
2.如果一个任务里有两个子任务,需要两个不同的入口函数(main_taskA.py, main_taskB.py),是否每个main里都应该有个fitlog.commit(file)?
3.我想学学你们是怎么操作git自动commit的。通常用gitpython这个库可以操作git,但你们好像没有用到。

memo一刷新就没了

用网页上的刷新键刷新没问题,但是用F5刷新后,自己添加的memo就没了

UnicodeDecodeError on Windows

When I followed the tutorial of fitlog, I met a bug at step3.
After I typed "fitlog log logs", I came across an error
"UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 36: illegal multibyte sequence"
at
"../fitlog/fastserver/server/log_config_parser.py", line 1042, in _read
for lineno, line in enumerate(fp, start=1):

So I modified the encoding at line 682.
Is there any better solution?

trend看train_loss,训练过程中无曲綫,横坐标为0到1

想试用下fitlog工具加在tf-yolov3代码里,由于代码中未计算mAP,只想看下train_loss曲綫。加的代码如下:
fitlog.add_loss(train_step_loss, name="train_loss", step=train_step)
loss.log中信息如下:
image

在网页中打开是这样的
image

image

是我操作有误吗?

在云上跑, 没有git, 无法使用

能否只让它收集loss, 参数等信息.
我尝试不使用fitlog.commit(file), 但依然无法使用, 会报 ImportError: Failed to initialize: Bad git executable.
好像是导入包时就会判断是否有git.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.