trainer_context.h 1.7 KB
Newer Older
X
xiexionghang 已提交
1 2 3 4
#pragma once
#include <string>
#include <memory>
#include <vector>
5
#include <sstream>
X
xiexionghang 已提交
6
#include "paddle/fluid/platform/place.h"
X
xiexionghang 已提交
7
#include "paddle/fluid/train/custom_trainer/feed/common/yaml_helper.h"
X
xiexionghang 已提交
8
#include "paddle/fluid/train/custom_trainer/feed/common/pslib_warpper.h"
X
xiexionghang 已提交
9 10 11 12 13 14 15 16
#include "paddle/fluid/train/custom_trainer/feed/common/runtime_environment.h"


namespace paddle {
namespace custom_trainer {
namespace feed {

class Process;
X
xiexionghang 已提交
17 18
class Dataset;
class FileSystem;
X
xiexionghang 已提交
19 20
class EpochAccessor;

X
xiexionghang 已提交
21 22 23 24
const uint32_t SecondsPerMin = 60;
const uint32_t SecondsPerHour = 3600;
const uint32_t SecondsPerDay = 24 * 3600;

X
xiexionghang 已提交
25 26 27 28 29 30
enum class ModelSaveWay {
    ModelSaveTrainCheckpoint = 0,
    ModelSaveInferenceDelta = 1,
    ModelSaveInferenceBase = 2
};

W
wangyihong01 已提交
31
class SignCacheDict {
X
xiexionghang 已提交
32
public:
W
wangyihong01 已提交
33 34 35 36 37 38
    int32_t sign2index(uint64_t sign) {
        return -1;
    }

    uint64_t index2sign(int32_t index) {
        return 0;
X
xiexionghang 已提交
39 40
    }
};
X
xiexionghang 已提交
41 42 43

class TrainerContext {
public:
X
xiexionghang 已提交
44 45 46 47 48 49 50 51
    inline paddle::ps::PSClient* ps_client() {
        return pslib->ps_client();
    }

    YAML::Node trainer_config;
    paddle::platform::CPUPlace cpu_place;

    std::shared_ptr<PSlib> pslib;
52
    std::stringstream monitor_ssm;                             //记录monitor信息
X
xiexionghang 已提交
53 54 55 56 57 58
    std::shared_ptr<Dataset> dataset;                          //训练样本
    std::shared_ptr<FileSystem> file_system;                   //文件操作辅助类
    std::shared_ptr<EpochAccessor> epoch_accessor;             //训练轮次控制
    std::shared_ptr<RuntimeEnvironment> environment;           //运行环境
    std::vector<std::shared_ptr<Process>> process_list;        //训练流程
    std::shared_ptr<SignCacheDict> cache_dict;                 //大模型cache词典
X
xiexionghang 已提交
59 60 61 62 63
};

}  // namespace feed
}  // namespace custom_trainer
}  // namespace paddle