intel-analytics / ipex-llm

Accelerate local LLM inference and finetuning (LLaMA, Mistral, ChatGLM, Qwen, Baichuan, Mixtral, Gemma, Phi, MiniCPM, etc.) on Intel CPU and GPU (e.g., local PC with iGPU, discrete GPU such as Arc, Flex and Max); seamlessly integrate with llama.cpp, Ollama, HuggingFace, LangChain, LlamaIndex, GraphRAG, DeepSpeed, vLLM, FastChat, Axolotl, etc.
Apache License 2.0
6.46k stars 1.24k forks source link

How to use BigDL to calculate MSE values #10831

Open gdg1212 opened 4 months ago

gdg1212 commented 4 months ago
val model = Sequential[Float]()
  .add(Dense(hiddenSize, inputShape = Shape(inputSize)))
  .add(Activation("relu"))
  .add(Dense(1))
val optimizer = Optimizer(model = model,
  sampleRDD = trainingTensor.map(_._2),
  criterion = MSECriterion[Float](),
  batchSize = 100000)

 optimizer
   .setOptimMethod(new Adam(0.001))
   .setEndWhen(Trigger.maxEpoch(100))
    .optimize()

I don't know how to calculate the MSE values of the training and testing sets through the model

qiuxin2012 commented 4 months ago

You can add a validation set to evaluate the model during the training, like: https://github.com/intel-analytics/BigDL-2.x/blob/b4cde76e58c3b97c69424f0c8bbc4c6d08879195/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/models/lenet/Train.scala#L99

And you can use validator to evalute your model after training, like: https://github.com/intel-analytics/BigDL-2.x/blob/b4cde76e58c3b97c69424f0c8bbc4c6d08879195/scala/dllib/src/test/scala/com/intel/analytics/bigdl/dllib/optim/ValidatorSpec.scala#L57-L60