• printVar

    printVar

    在 hogWildWorker 里训练的时候 printVar
    1. void HogwildWorker::PrintFetchVars() {
    2. // call count
    3. batch_num_++;
    4. int batch_per_print = fetch_config_.print_period();
    5. if (thread_id_ == 0) {
    6. if (batch_num_ % batch_per_print == 0) {
    7. int fetch_var_num = fetch_config_.fetch_var_names_size();
    8. for (int i = 0; i < fetch_var_num; ++i) {
    9. platform::PrintVar(thread_scope_, fetch_config_.fetch_var_names(i),
    10. fetch_config_.fetch_var_str_format(i));
    11. }
    12. }
    13. }
    14. }
    再看看 platform::PrintVars 的逻辑:
    1. void PrintVar(framework::Scope* scope, const std::string& var_name,
    2. const std::string& print_info) {
    3. framework::Variable* var = scope->FindVar(var_name);
    4. if (var == nullptr) {
    5. VLOG(1) << "Variable Name " << var_name << " does not exist in your scope";
    6. return;
    7. }
    8. framework::LoDTensor* tensor = var->GetMutable<framework::LoDTensor>();
    9. if (tensor == nullptr) {
    10. VLOG(1) << "tensor of variable " << var_name
    11. << " does not exist in your scope";
    12. return;
    13. }
    14. std::ostringstream sstream;
    15. sstream << print_info << "\t";
    16. sstream << var_name << "\t";
    17. sstream << *tensor << "\t";
    18. std::cout << sstream.str() << std::endl;
    19. }