TypeError: forward() missing 2 required positional arguments: 'y_orders' and 'beta'

amir240: <p>Hello,</p>
<p>I am using the following code from hgraph2graph and I am getting an error message for missing arguments. Can you please help to solve this error.</p>
<p>Thanks,</p>
<p>Traceback (most recent call last):<br>
File “/apps/hgraph2graph/20210428/hgraph2graph/train_translator.py”, line 86, in <br>
loss, kl_div, wacc, iacc, tacc, sacc = model(*batch)<br>
File “/apps/hgraph2graph/20210428/lib/python3.7/site-packages/torch/nn/modules/module.py”, line 1110, in _call_impl<br>
return forward_call(*input, **kwargs)<br>
TypeError: forward() missing 2 required positional arguments: ‘y_orders’ and ‘beta’</p>
<p>import torch<br>
import torch.nn as nn<br>
import torch.optim as optim<br>
import torch.optim.lr_scheduler as lr_scheduler<br>
from torch.utils.data import DataLoader</p>
<p>import math, random, sys<br>
import numpy as np<br>
import argparse</p>
<p>from hgraph import *<br>
import rdkit</p>
<p>lg = rdkit.RDLogger.logger()<br>
lg.setLevel(rdkit.RDLogger.CRITICAL)</p>
<p>parser = argparse.ArgumentParser()<br>
parser.add_argument(‘–train’, required=True)<br>
parser.add_argument(‘–vocab’, required=True)<br>
parser.add_argument(‘–atom_vocab’, default=common_atom_vocab)<br>
parser.add_argument(‘–save_dir’, required=True)<br>
parser.add_argument(‘–load_epoch’, type=int, default=-1)</p>
<p>parser.add_argument(‘–conditional’, action=‘store_true’)<br>
parser.add_argument(‘–cond_size’, type=int, default=4)</p>
<p>parser.add_argument(‘–rnn_type’, type=str, default=‘LSTM’)<br>
parser.add_argument(‘–hidden_size’, type=int, default=270)<br>
parser.add_argument(‘–embed_size’, type=int, default=270)<br>
parser.add_argument(‘–batch_size’, type=int, default=32)<br>
parser.add_argument(‘–latent_size’, type=int, default=4)<br>
parser.add_argument(‘–depthT’, type=int, default=20)<br>
parser.add_argument(‘–depthG’, type=int, default=20)<br>
parser.add_argument(‘–diterT’, type=int, default=1)<br>
parser.add_argument(‘–diterG’, type=int, default=3)<br>
parser.add_argument(‘–dropout’, type=float, default=0.0)</p>
<p>parser.add_argument(‘–lr’, type=float, default=1e-3)<br>
parser.add_argument(‘–clip_norm’, type=float, default=20.0)<br>
parser.add_argument(‘–beta’, type=float, default=0.3)</p>
<p>parser.add_argument(‘–epoch’, type=int, default=12)<br>
parser.add_argument(‘–anneal_rate’, type=float, default=0.9)<br>
parser.add_argument(‘–print_iter’, type=int, default=50)<br>
parser.add_argument(‘–save_iter’, type=int, default=-1)</p>
<p>args = parser.parse_args()<br>
print(args)</p>
<p>vocab = [x.strip("\r\n ").split() for x in open(args.vocab)]<br>
args.vocab = PairVocab(vocab)<br>
if args.conditional:<br>
model = HierCondVGNN(args).cuda()<br>
else:<br>
model = HierVGNN(args).cuda()</p>
<p>for param in model.parameters():<br>
if param.dim() == 1:<br>
nn.init.constant_(param, 0)<br>
else:<br>
nn.init.xavier_normal_(param)</p>
<p>if args.load_epoch &gt;= 0:<br>
model.load_state_dict(torch.load(args.save_dir + “/model.” + str(args.load_epoch)))</p>
<p>print(“Model <span class="hashtag">#Params:</span> %dK” % (sum([x.nelement() for x in model.parameters()]) / 1000,))</p>
<p>optimizer = optim.Adam(model.parameters(), lr=args.lr)<br>
scheduler = lr_scheduler.ExponentialLR(optimizer, args.anneal_rate)</p>
<p>param_norm = lambda m: math.sqrt(sum([p.norm().item() ** 2 for p in m.parameters()]))<br>
grad_norm = lambda m: math.sqrt(sum([p.grad.norm().item() ** 2 for p in m.parameters() if p.grad is not None]))</p>
<p>total_step = 0<br>
beta = args.beta<br>
meters = np.zeros(6)</p>
<p>for epoch in range(args.load_epoch + 1, args.epoch):<br>
dataset = DataFolder(args.train, args.batch_size)</p>
<pre><code>for batch in dataset:
    total_step += 1
    batch = batch + (beta,)
    model.zero_grad()
    loss, kl_div, wacc, iacc, tacc, sacc = model(*batch)

    loss.backward()
    nn.utils.clip_grad_norm_(model.parameters(), args.clip_norm)
    optimizer.step()

    meters = meters + np.array([kl_div, loss.item(), wacc.cpu() * 100, iacc.cpu() * 100, tacc.cpu() * 100, sacc.cpu() * 100])
</code></pre>
<h1>
<a name="meters-meters-nparraykl_div-lossitem-wacc-100-iacc-100-tacc-100-sacc-100-1" class="anchor" href="#meters-meters-nparraykl_div-lossitem-wacc-100-iacc-100-tacc-100-sacc-100-1"></a>meters = meters + np.array([kl_div, loss.item(), wacc * 100, iacc * 100, tacc * 100, sacc * 100])</h1>
<pre><code>    if total_step % args.print_iter == 0:
        meters /= args.print_iter
        print("[%d] Beta: %.3f, KL: %.2f, loss: %.3f, Word: %.2f, %.2f, Topo: %.2f, Assm: %.2f, PNorm: %.2f, GNorm: %.2f" % (total_step, beta, meters[0], meters[1], meters[2], meters[3], meters[4], meters[5], param_norm(model), grad_norm(model)))
        sys.stdout.flush()
        meters *= 0
   if args.save_iter &gt;= 0 and total_step % args.save_iter == 0:
        n_iter = total_step // args.save_iter - 1
        torch.save(model.state_dict(), args.save_dir + "/model." + str(n_iter))
        scheduler.step()
        print("learning rate: %.6f" % scheduler.get_lr()[0])

del dataset
if args.save_iter == -1:
    torch.save(model.state_dict(), args.save_dir + "/model." + str(epoch))
    scheduler.step()
    print("learning rate: %.6f" % scheduler.get_lr()[0])
</code></pre>

Andrew_Edmondson: <p>What does the model’s forward() method look like that is called by this line?</p>
<aside class="quote no-group" data-username="amir240" data-post="1" data-topic="156290">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/a/7bcc69/48.png" class="avatar"> amir240:</div>
<blockquote>
<p><code> loss, kl_div, wacc, iacc, tacc, sacc = model(*batch)</code></p>
</blockquote>
</aside>

amir240: <p>How can I get this information?</p>