Keras-style MapTable container

18 views
Skip to first unread message

Phuong LE-HONG

unread,
Jan 20, 2024, 10:08:58 AMJan 20
to BigDL User Group
Hi all,

I'm building a BigDL module using Keras-style layers. I'd like to use the same submodule for all inputs of a table. 

The nn package of BigDL has the MapTable container which does exactly what I am looking for. It is for a single module which will be applied to all input elements. The member module is cloned to process all input elements.

It seems to me that the Keras-style does not have such a container. Or am I missing something?

If it does not have MapTable, is there an alternative approach to have the same functionality?

Thank you for your information.

Best

Phuong
 

huangka...@gmail.com

unread,
Jan 21, 2024, 9:21:49 PMJan 21
to User Group for BigDL

Phuong LE-HONG

unread,
Jan 22, 2024, 11:58:25 PMJan 22
to huangka...@gmail.com, User Group for BigDL
Dear Kai,

Thanks for your reply. I still have difficulty wrapping the MapTable. Here is my problem. Say I have a table of 10 elements, each is a tensor of shape 1 x 5 x 4. I'd like to apply a GRU(3) to each element to get a tensor of shape 1 x 3. After that, all the states are concatenated/merged to get the final tensor of shape 10 x 3.

The code I am using is as follows:

val gru = GRU(3)
val mapTableGRU = MapTable(gru)
val mapTableGRUKeras = new KerasLayerWrapper[Float](mapTableGRU.asInstanceOf[AbstractModule[Activity, Activity, Float]])
mapTableGRUKeras.build(KerasUtils.addBatch(Shape(1, 5, 4)))
val mtgNode = mapTableGRUKeras.inputs(split) // point to the SplitTensor node which provides a table with 10 elements

===

The build() method raises the error:

[E] Exception in thread "main" com.intel.analytics.bigdl.dllib.utils.UnKnownException: MapTable[e9f43ef2]{
[E]   GRU[3e10a1f]
[E] }
[E] com.intel.analytics.bigdl.dllib.tensor.DenseTensor cannot be cast to com.intel.analytics.bigdl.dllib.utils.Table
[E] at com.intel.analytics.bigdl.dllib.utils.Log4Error$.unKnowExceptionError(Log4Error.scala:60)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.AbstractModule.forward(AbstractModule.scala:295)
[E] at com.intel.analytics.bigdl.dllib.keras.layers.LayerWrapperByForward$.computeOutputShape(KerasLayerWrapper.scala:93)
[E] at com.intel.analytics.bigdl.dllib.keras.layers.LayerWrapperByForward.computeOutputShape(KerasLayerWrapper.scala:46)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.InferShape.build(InferShape.scala:76)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.InferShape.build$(InferShape.scala:75)
[E] at com.intel.analytics.bigdl.dllib.nn.internal.KerasLayer.build(KerasLayer.scala:316)

===

I think that there is something wrong with the input shape to the MapTable wrapper here but I have not found the problem yet. The SplitTensor node gives me a table. 

I tried to build() the gru instead of the wrapper, as follows:

val gru = GRU(3)
gru..build(KerasUtils.addBatch(Shape(5, 4)))
val mapTableGRU = MapTable(gru)
val mapTableGRUKeras = new KerasLayerWrapper[Float](mapTableGRU.asInstanceOf[AbstractModule[Activity, Activity, Float]])
// mapTableGRUKeras.build(KerasUtils.addBatch(Shape(1, 5, 4)))
val mtgNode = mapTableGRUKeras.inputs(split) // point to the SplitTensor node which provides a table with 10 elements

The the last line raises a different error:

[E] Exception in thread "main" com.intel.analytics.bigdl.dllib.utils.InvalidOperationException: Recurrent: input should be a 3D/5D/6D Tensor, e.g [batch, times, nDim], current input.dim = 4
[E] at com.intel.analytics.bigdl.dllib.utils.Log4Error$.invalidOperationError(Log4Error.scala:38)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.AbstractModule.forward(AbstractModule.scala:291)
[E] at com.intel.analytics.bigdl.dllib.keras.layers.LayerWrapperByForward$.computeOutputShape(KerasLayerWrapper.scala:93)
[E] at com.intel.analytics.bigdl.dllib.keras.layers.LayerWrapperByForward.computeOutputShape(KerasLayerWrapper.scala:46)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.InferShape.build(InferShape.scala:76)
[E] at com.intel.analytics.bigdl.dllib.nn.abstractnn.InferShape.build$(InferShape.scala:75)
[E] at com.intel.analytics.bigdl.dllib.nn.internal.KerasLayer.build(KerasLayer.scala:316)
[E] at com.intel.analytics.bigdl.dllib.nn.internal.KerasLayer.inputs(KerasLayer.scala:333)

It's not easy to wrap a MapTable, I think. Should the Keras-style MapTable be added to the next version of BigDL?

Thanks for your advice.

Phuong


--
You received this message because you are subscribed to the Google Groups "User Group for BigDL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bigdl-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/32c74218-3ce4-44c5-84d3-19a47c04b55en%40googlegroups.com.

huangka...@gmail.com

unread,
Jan 25, 2024, 6:53:22 AMJan 25
to User Group for BigDL
Hi Phuong,

Sorry that we don't have plan to support this at this moment. We will notify you when we have bandwidth to add it in the future.

Thanks,
Kai
Reply all
Reply to author
Forward
0 new messages