Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubts about ParallelTable and ParallelCriterion #12278

Open
clare-cn opened this issue Oct 26, 2024 · 0 comments
Open

Doubts about ParallelTable and ParallelCriterion #12278

clare-cn opened this issue Oct 26, 2024 · 0 comments

Comments

@clare-cn
Copy link

clare-cn commented Oct 26, 2024

I am a beginner using BigDL to create a ParallelTable model for training, but I encountered errors in converting between Tensor and Table types:
Caused by: java. lang. ClassCastException: com. intel. analytics. bigdl. dllib. utilities Table cannot be cast to com.intel.analytics.bigdl.dllib.tensor.Tensor.
I have used Graph (Input [Float(), Sigmoid [Float())) models before, with a loss function of MSERiterion [Float()) and training data input of DataSet [Sample [Float] (Tensor (features, Array (features. length), Tensor (Array (label), Array (1)), can work normally. But now, I am confused about this. Is there a problem with my training data type (but Sample only accepts Tensor types)? Or is there a problem with my model construction? I don't know how to solve it now, I hope to receive some help
My partial code is as follows:

val modelTask1 = Sequential()
.add(SequentialFloat
.add(Linear(200, 100))
.add(ReLUFloat))
.add(Linear(100, 1))
val modelTask2 = Sequential()
.add(SequentialFloat
.add(Linear(200, 100))
.add(ReLUFloat))
.add(Linear(100, 1))

val model = ParallelTable()
.add(modelTask1)
.add(modelTask2)
val trainData = DataSet.rdd(trainDf.rdd.map(row => {
val features = row.getAsDenseVector.toArray.map(_.toFloat)
val ctr = row.getAsDouble.toFloat
val cvr = row.getAsDouble.toFloat
Sample[Float](Tensor(features, Array(features.length)), Tensor(Array(ctr, cvr), Array(2)))
})).transform(SampleToMiniBatchFloat)

val criterion = ParallelCriterionFloat
criterion.add(MSECriterionFloat, 1.0)
criterion.add(MSECriterionFloat, 1.0)
val optimizer = Optimizer(
model = model,
dataset = trainData,
criterion = criterion
).setOptimMethod(new AdamFloat)
.setEndWhen(Trigger.maxEpoch(maxEpoch.toInt))
val trainedModel = optimizer.optimize()

@clare-cn clare-cn changed the title Doubts about Tensor and Table types Doubts about ParallelTable and ParallelCriterion Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants