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

nn.ModuleList[ParamType] can not append add nn.Embedding layer #83

Open
mullerhai opened this issue Jan 14, 2025 · 0 comments
Open

nn.ModuleList[ParamType] can not append add nn.Embedding layer #83

mullerhai opened this issue Jan 14, 2025 · 0 comments

Comments

@mullerhai
Copy link

HI,
I want to use one modelList to contain many layer, for Embedding layer ,why can not contain it ?

import torch.*
import torch.nn.modules.{HasParams, TensorModule}


class MultiLayerPerceptron[ParamType <: FloatNN : Default](input_dim: Long, embed_dims: Seq[Int], dropout: Double, output_layer: Boolean = true) extends HasParams[ParamType]
  with TensorModule[ParamType] {

  val layers = nn.ModuleList[ParamType]()
  embed_dims.zipWithIndex.foreach {
    case (embed_dim, index) => {
      val block = register(LinearBnReluDropBlock(input_dim, embed_dim, dropout))
      layers.append(block)
    }
  }
  if (output_layer) {
    var output_linear = register(nn.Linear(input_dim, 1))
    layers.append(output_linear)
  }
  layers.append(nn.Embedding(10, 45))

console log error

MultiLayerPerceptron.scala:24:17
Found:    torch.nn.modules.sparse.Embedding[ParamType]
Required: torch.nn.modules.TensorModule[ParamType]
  layers.append(nn.Embedding(10, 45))

but nn.Embedding layer is TensorModule's sub class ,why linear and conv2d could add ? is cause by the layer class Type parameters ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant