How to write a model / loss function where the loss is calculated in external tool.
I wrote a psedocode to illustrate what I want to achieve:
model = CustomModel().to(device) # Lets say 1000 inputs and 10 outputs

optimizer = optim.Adam(model.parameters(), lr=0.01)

inputs = next(iter(trainloader))

model_out = model(inputs) # 10 values that will be used to calculate loss

save_outs_to_file('model_out.txt', model_out)

proc = subprocess.Popen(["./calculate_loss", "-i", "model_out.txt"], stdout=subprocess.PIPE)
loss = proc.stdout.read()

# What to do next with this loss? 
# How to perform backprop?
# ... .backward()

optimizer.step()