fitlog.fastlog package¶
fastlog 是 fitlog 的一部分,用于帮助用户进行日志管理。fastlog 默认使用工作目录下的 logs 文件做为存储和配置路径。 默认配置文件为default.cfg。用户可以使用 fitlog 命令行工具初始化项目,启动服务器,并在网页上查看日志。
fitlog.fastlog.log_read module¶
-
class
fitlog.fastlog.log_read.
LogReader
[源代码]¶ 基类:
object
用于读取日志的类, 用于配合Table使用
-
fitlog.fastlog.log_read.
is_log_dir_has_step
(_save_log_dir: str, check_files='metric.log', 'loss.log') → bool[源代码]¶ 给定log_dir, 判断是否有step数据
:param _save_log_dir 日志存放的目录 :param check_files: 检查file是否含有step :return: 是否有step数据
-
fitlog.fastlog.log_read.
merge
(a: dict, b: dict, use_b: bool = True) → dict[源代码]¶ 将两个dict recursive合并到a中,有相同key的,根据use_b判断使用哪个值
- 参数
a -- 字典 a
b -- 字典 b
use_b -- 是否使用字典 b 的值
- 返回
返回字典 a
-
fitlog.fastlog.log_read.
is_dirname_log_record
(dir_path: str) → bool[源代码]¶ 检查dir_path是否是一个合法的log目录。合法的log目录里必须包含meta.log。
- 参数
dir_path -- 被检测的路径
- 返回
是否合法
-
fitlog.fastlog.log_read.
is_log_record_finish
(save_log_dir: str) → bool[源代码]¶ 检测日志的记录是否已经结束
- 参数
save_log_dir -- 日志存放的目录
- 返回
-
class
fitlog.fastlog.log_read.
StandbyStepLogReader
(save_log_dir: str, uuid: str, wait_seconds: int = 60, max_no_updates: int = 30)[源代码]¶ 基类:
threading.Thread
用于多线程读取日志的类. 配合画图使用的。
- 参数
save_log_dir -- 日志存放的目录
uuid -- 用于唯一识别 Reader 的 uuid
wait_seconds -- 在文件关闭后再等待{wait_seconds}秒结束进程
max_no_updates -- 在{max_no_updates}次都没有更新时结束进程
-
static
read_update_single_log
(filepaths: List[str], ranges: dict) → dict[源代码]¶ 调用这个函数,获取filepaths中满足range_min, range_max的log
- 参数
filepaths -- 完整的path路径
ranges -- {'metric':[min, max] }
- 返回
返回值的结构如下。loss这个list是进行了step排序的
{ loss: [dict('step':x, epoch:value, 'loss':{'loss1':xx})], metric:[dict('step':x, epoch:value, 'metric':{'SpanFMetric':{'f':xx}})] }
-
read_update
(only_once: bool = False, handler_names='metric', 'loss') → dict[源代码]¶ 调用这个函数,获取新的更新。如果第一次调用则是读取到当前所有的记录。
- 参数
only_once -- 是否只读取内容一次。是的话就不会保持读取到的行数,之后直接退出了
handler_names -- 只check包含在handler_name的内容
- 返回
返回值的结构如下
{ loss: [dict('step':x, epoch:value, 'loss':{}), ...], # 或[dict('step':x, epoch:value, 'loss':value), ...] metric:[dict('step':x, epoch:value, 'metric':{'SpanFMetric':xxx})], finish:bool(not every time), total_steps:int(only the first access) }
fitlog.fastlog.logger module¶
-
class
fitlog.fastlog.logger.
FitlogConfig
(**kwargs)[源代码]¶ 基类:
object
用于add_hyper函数的基类。 继承后无需实例化直接传入add_hyper。
-
class
fitlog.fastlog.logger.
Logger
[源代码]¶ 基类:
object
用于处理日志的类,fitlog 的核心
-
set_rng_seed
(rng_seed: int = None, random: bool = True, numpy: bool = True, pytorch: bool = True, deterministic: bool = True)[源代码]¶ - 设置模块的随机数种子。由于pytorch还存在cudnn导致的非deterministic的运行,所以一些情况下可能即使seed一样,结果也不一致
需要在fitlog.commit()或fitlog.set_log_dir()之后运行才会记录该rng_seed到log中
- 参数
rng_seed (int) -- 将这些模块的随机数设置到多少,默认为随机生成一个。
random (bool,) -- 是否将python自带的random模块的seed设置为rng_seed.
numpy (bool,) -- 是否将numpy的seed设置为rng_seed.
pytorch (bool,) -- 是否将pytorch的seed设置为rng_seed(设置torch.manual_seed和torch.cuda.manual_seed_all).
deterministic (bool,) -- 是否将pytorch的torch.backends.cudnn.deterministic设置为True
-