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

javacpp- pytorch transformerimpl lack some parameter between with python pytorch and cpp libtorch #1582

Open
mullerhai opened this issue Feb 21, 2025 · 0 comments

Comments

@mullerhai
Copy link

Hi,
I find javacpp-pytorch some layer impl not the same as python pytorch and cpp libtorch ,like transformer layer

https://pytorch.org/docs/stable/generated/torch.nn.Transformer.html


Transformer
CLASStorch.nn.Transformer(d_model=512, nhead=8, num_encoder_layers=6, num_decoder_layers=6, dim_feedforward=2048, dropout=0.1, activation=<function relu>, custom_encoder=None, custom_decoder=None, layer_norm_eps=1e-05, batch_first=False, norm_first=False, bias=True, device=None, dtype=None)


but javacpp TransformerImpl lack [layer_norm_eps=1e-05, batch_first=False, norm_first=False, ] three parameter not supply ,so how to pass these parameter in javacpp


  public TransformerOptions(
        @Cast("int64_t") long d_model,
        @Cast("int64_t") long nhead,
        @Cast("int64_t") long num_encoder_layers,
        @Cast("int64_t") long num_decoder_layers) { super((Pointer)null); allocate(d_model, nhead, num_encoder_layers, num_decoder_layers); }
  private native void allocate(
        @Cast("int64_t") long d_model,
        @Cast("int64_t") long nhead,
        @Cast("int64_t") long num_encoder_layers,
        @Cast("int64_t") long num_decoder_layers);
  public native @Cast("int64_t*") @ByRef @NoException(true) LongPointer d_model();
  public native @Cast("int64_t*") @ByRef @NoException(true) LongPointer nhead();
  public native @Cast("int64_t*") @ByRef @NoException(true) LongPointer num_encoder_layers();
  public native @Cast("int64_t*") @ByRef @NoException(true) LongPointer num_decoder_layers();
  public native @Cast("int64_t*") @ByRef @NoException(true) LongPointer dim_feedforward();
  public native @ByRef @NoException(true) DoublePointer dropout();
  public native @ByRef @NoException(true) TransformerActivation activation();
  public native @ByRef @NoException(true) AnyModule custom_encoder();
  public native @ByRef @NoException(true) AnyModule custom_decoder();

class Transformer dModel:Long =512 ,nhead:Long = 8, numEncoderLayers:Long=6,numDecoderLayers:Long=6,
                                                                     dimFeedforward :Long=2048,dropout:Double=0.1,
                                                                    customEncoder:Option[AnyModule] = None,
                                                                    customDecoder:Option[AnyModule] = None,
                                                                    activation: TransformerActivation ,bias: Boolean = true

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