Esempio n. 1
0
 virtual void InitSolverFromProtoString(const string& proto) {
   SolverParameter param;
   CHECK(google::protobuf::TextFormat::ParseFromString(proto, &param));
   // Set the solver_mode according to current Caffe::mode.
   switch (Caffe::mode()) {
     case Caffe::CPU:
       param.set_solver_mode(SolverParameter_SolverMode_CPU);
       break;
     case Caffe::GPU:
       param.set_solver_mode(SolverParameter_SolverMode_GPU);
       break;
     default:
       LOG(FATAL) << "Unknown Caffe mode: " << Caffe::mode();
   }
   solver_.reset(new SGDSolver<Dtype>(param));
 }
Esempio n. 2
0
SolverParameter ModelServer<Dtype>::prepare_model() {
  NetParameter net;
  solver->net()->ToProto(&net);

  for (int i = 0; i < net.layer_size(); ++i) {
    LayerParameter& layer = *net.mutable_layer(i);
    layer.clear_blobs();
    if ((layer.type().find("Data") != std::string::npos)
        && (layer.has_remote_data_param())) {
      layer.set_type("RemoteData");

      for (int j = 0; j < layer.top_size(); ++j) {
        *layer.mutable_remote_data_param()->add_shape()
          = blob_shape_by_name(layer.top(j));
      }
    }
  }

  SolverParameter ret = solver->param();
  ret.clear_net();
  ret.clear_net_param();
  ret.clear_test_net();
  ret.clear_test_net_param();
  ret.clear_train_net();
  *ret.mutable_train_net_param() = net;

  return ret;
}
Esempio n. 3
0
P2PSync<Dtype>::P2PSync(shared_ptr<Solver<Dtype> > root_solver,
                        P2PSync<Dtype>* parent, const SolverParameter& param)
    : GPUParams<Dtype>(root_solver, param.device_id()),
      parent_(parent),
      children_(),
      queue_(),
      initial_iter_(root_solver->iter()),
      solver_() {
#ifndef CPU_ONLY
    int initial_device;
    CUDA_CHECK(cudaGetDevice(&initial_device));
    const int self = param.device_id();
    CUDA_CHECK(cudaSetDevice(self));

    if (parent == NULL) {
        solver_ = root_solver;
    } else {
        Caffe::set_root_solver(false);
        solver_.reset(new WorkerSolver<Dtype>(param, root_solver.get()));
        Caffe::set_root_solver(true);
    }
    this->configure(solver_.get());
    solver_->add_callback(this);

    if (parent) {
        // Enable p2p access between devices
        const int peer = parent->solver_->param().device_id();
        int access;
        CUDA_CHECK(cudaDeviceCanAccessPeer(&access, self, peer));
        if (access) {
            CUDA_CHECK(cudaDeviceEnablePeerAccess(peer, 0));
        } else {
            LOG(INFO)<< "GPU " << self << " does not have p2p access to GPU " << peer;
        }
        // Allocate receiving buffer on parent
        CUDA_CHECK(cudaSetDevice(peer));
        CUDA_CHECK(cudaMalloc(&parent_grads_, size_ * sizeof(Dtype)));
        CUDA_CHECK(cudaSetDevice(self));
    }

    CUDA_CHECK(cudaSetDevice(initial_device));
#else
    NO_GPU;
#endif
}
Esempio n. 4
0
int
SolverHooks::setOption(const char *optionname, Value val, Simulation *S){
	/* FIXME need to check if the system is built? */
	/* FIXME check if we have got a solver assigned? */
	SolverParameters pp = S->getParameters();

	try{
		SolverParameter p = pp.getParameter(optionname);
		try{
			p.setValueValue(val);
		}catch(std::runtime_error E){
			return SLVREQ_WRONG_OPTION_VALUE_TYPE;
		}
	}catch(std::runtime_error E){
		return SLVREQ_INVALID_OPTION_NAME;
	}
	return 0;
}
Esempio n. 5
0
 virtual void InitSolverFromProtoString(const string& proto) {
   SolverParameter param;
   CHECK(google::protobuf::TextFormat::ParseFromString(proto, &param));
   // Disable saving a final snapshot so the tests don't pollute the user's
   // working directory with useless snapshots.
   param.set_snapshot_after_train(false);
   // Set the solver_mode according to current Caffe::mode.
   switch (Caffe::mode()) {
     case Caffe::CPU:
       param.set_solver_mode(SolverParameter_SolverMode_CPU);
       break;
     case Caffe::GPU:
       param.set_solver_mode(SolverParameter_SolverMode_GPU);
       break;
     default:
       LOG(FATAL) << "Unknown Caffe mode: " << Caffe::mode();
   }
   solver_.reset(new MockSGDSolver(param));
 }
 virtual void InitSolverFromProtoString(const string& proto) {
   SolverParameter param;
   CHECK(google::protobuf::TextFormat::ParseFromString(proto, &param));
   // Set the solver_mode according to current Caffe::mode.
   switch (Caffe::mode()) {
     case Caffe::CPU:
       param.set_solver_mode(SolverParameter_SolverMode_CPU);
       break;
     case Caffe::GPU:
       param.set_solver_mode(SolverParameter_SolverMode_GPU);
       break;
     default:
       LOG(FATAL) << "Unknown Caffe mode: " << Caffe::mode();
   }
   InitSolver(param);
   delta_ = (solver_type() == SolverParameter_SolverType_ADAGRAD ||
       solver_type() == SolverParameter_SolverType_RMSPROP) ?
       param.delta() : 0;
 }
Esempio n. 7
0
void Solver<Dtype>::Init(const SolverParameter& param) {
  LOG(INFO) << "Initializing solver from parameters: " << std::endl
            << param.DebugString();
  param_ = param;
  if (param_.random_seed() >= 0) {
    Caffe::set_random_seed(param_.random_seed());
  }
  // Scaffolding code
  InitTrainNet();
  InitTestNets();
  LOG(INFO) << "Solver scaffolding done.";
}
Esempio n. 8
0
void Solver<Dtype>::Init(const SolverParameter& param) {
  LOG(INFO) << "Initializing solver from parameters: " << std::endl
            << param.DebugString();
  param_ = param;
  CHECK_GE(param_.average_loss(), 1) << "average_loss should be non-negative.";
  if (param_.random_seed() >= 0) {
    Caffe::set_random_seed(param_.random_seed());
  }
  // Scaffolding code
  InitTrainNet();
  InitTestNets();
  LOG(INFO) << "Solver scaffolding done.";
  iter_ = 0;
  current_step_ = 0;
}
Esempio n. 9
0
void Solver<Dtype>::Init(const SolverParameter& param) {
  CHECK(Caffe::root_solver() || root_solver_)
      << "root_solver_ needs to be set for all non-root solvers";
  LOG_IF(INFO, Caffe::root_solver()) << "Initializing solver from parameters: "
    << std::endl << param.DebugString();
  param_ = param;
  CHECK_GE(param_.average_loss(), 1) << "average_loss should be non-negative.";
  CheckSnapshotWritePermissions();
  if (Caffe::root_solver() && param_.random_seed() >= 0) {
    Caffe::set_random_seed(param_.random_seed());
  }
  // Scaffolding code
  InitTrainNet();
  if (Caffe::root_solver()) {
    InitTestNets();
    LOG(INFO) << "Solver scaffolding done.";
  }
  iter_ = 0;
  current_step_ = 0;
}
Esempio n. 10
0
const string
SolverParameters::toString() const{
	stringstream ss;
	ss << "SOLVERPARAMETERS:TOSTRING:" << endl;
	ss << "Number of parameters: " << p.num_parms << endl;

	iterator i;
	for(i = begin(); i<end(); ++i){
		SolverParameter p = *i;
#if 0
		ss << p.getLabel() << " [" << p.getDescription() << "]: ";
#else
		ss << p.getName() << ": ";
#endif
		if(p.isInt()){
			ss << p.getIntValue();
		}else if(p.isReal()){
			ss << p.getRealValue();
		}else if(p.isBool()){
			ss << (p.getBoolValue() ? "true" : "false");
		}else if(p.isStr()){
			ss << p.getStrValue();
		}else{
			throw runtime_error("Unhandled case");
		}
		ss << endl;
	}
	return ss.str();
}