RuntimeError: lhs of assignment must be a variable, subscript, or starred expression:

jiacheng1gujiaxin: <p>after i QAT my model,  i tried to save it with torch.jit.save<br>
but it did not work:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/0/6017a36f06a889f59a605d49f9d243a32b53c5dc.png" data-download-href="https://discuss.pytorch.org/uploads/default/6017a36f06a889f59a605d49f9d243a32b53c5dc" title="21"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/0/6017a36f06a889f59a605d49f9d243a32b53c5dc_2_690x374.png" alt="21" data-base62-sha1="dI4tTGHrvgPWrip3uakF2HzQXA8" width="690" height="374" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/0/6017a36f06a889f59a605d49f9d243a32b53c5dc_2_690x374.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/0/6017a36f06a889f59a605d49f9d243a32b53c5dc_2_1035x561.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/6/0/6017a36f06a889f59a605d49f9d243a32b53c5dc.png 2x" data-dominant-color="88E3B0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">21</span><span class="informations">1163×631 139 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/6/161a7dd9faaeafb40851a996d73c2c221c8853e1.png" data-download-href="https://discuss.pytorch.org/uploads/default/161a7dd9faaeafb40851a996d73c2c221c8853e1" title="22"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/1/6/161a7dd9faaeafb40851a996d73c2c221c8853e1_2_690x405.png" alt="22" data-base62-sha1="39xgguZ6Bi7zTYUCrRWeR6gPRpn" width="690" height="405" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/1/6/161a7dd9faaeafb40851a996d73c2c221c8853e1_2_690x405.png, https://discuss.pytorch.org/uploads/default/optimized/3X/1/6/161a7dd9faaeafb40851a996d73c2c221c8853e1_2_1035x607.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/1/6/161a7dd9faaeafb40851a996d73c2c221c8853e1_2_1380x810.png 2x" data-dominant-color="91F2BB"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">22</span><span class="informations">1562×918 128 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

albanD: <p>Hi,</p>
<p>Would you have a small code snippet that reproduces the crash please?</p>

jiacheng1gujiaxin: <blockquote>
<p>if args.qat:<br>
configure(args.log_dir, flush_secs=5)<br>
model.qconfig = torch.quantization.get_default_qat_qconfig(‘fbgemm’)<br>
torch.quantization.prepare_qat(model, inplace=True)<br>
# print(qat_model.parameters())</p>
<pre><code>optimizer = torch.optim.SGD(model.parameters(), lr=args.lr)
best_loss = 100
for nepoch in range(args.epochs):
    model.to(device)
    train_one_epoch(nepoch, model, criterion, optimizer, data_loader, device)
    if nepoch &gt; 90:
        # Freeze quantizer parameters
        model.apply(torch.quantization.disable_observer)
    if nepoch &gt; 95:
        # Freeze batch norm mean and variance estimates
        model.apply(torch.nn.intrinsic.qat.freeze_bn_stats)

    # Check the accuracy after each epoch
    model.to('cpu')
    quantized_model = torch.quantization.convert(model.eval(), inplace=False)
    quantized_model.eval()
    size = get_size_of_model(quantized_model)
    top1, top5, loss = evaluate(quantized_model, data_loader_test)
    if loss &lt; best_loss:
        best_loss = loss
        # torch.jit.save(torch.jit.script(quantized_model), 'quantizated_best.pth')
        torch.save(quantized_model.state_dict(), 'quantizated_best.pkl')
    print(
        f'Epoch {nepoch} | top1: {top1} | top5: {top5} | loss {loss} | size {size}')

    log_value('Validating/Accuracy', top1, nepoch)
    log_value('Validating/Loss', loss, nepoch)
    torch.jit.save(torch.jit.script(quantized_model), 'quantizated_final.pth')
</code></pre>
</blockquote>
<p>everything is ok except the process of ‘torch.jit.save()’</p>

jiacheng1gujiaxin: <p>I already solve this problem, thank you !!!</p>
<p>there is empty nn.Squentional() in my module, which torch.quantized.convert can`t remove (observer) from it,</p>
<p>so I remove it manually, and it works</p>

jerryzh168: <p>btw, we have a fix for empty sequential as well: <a href="https://github.com/pytorch/pytorch/pull/28384" rel="nofollow noopener">https://github.com/pytorch/pytorch/pull/28384</a></p>