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


namespace paddle {
namespace custom_trainer {
namespace feed {

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

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

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

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

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

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

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

    std::shared_ptr<PSlib> pslib;
    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 已提交
57 58 59 60 61
};

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