Per-batch loss for semi-supervised learning

The losses shown e.g. here don’t seem to have access to the entire batch but rather only single x,y values, if I understood correctly.
Another example here , and the forum won’t let me post a third link as I am too new.
Anyway while I am happy to try writing the loss (which iiuc would require implementing forward and backward methods as in the first link) I think it may not have access to the full batch, which I need for this case. I’ll try implementing a simple example, perhaps the x,y are batches of input,output and not individuals.

Also now that I think of it, differentiating max(f(x1),f(x2),…) is not obvious for me. I suppose I can just select the max of f and then evaluate the derivative for this point only.

At a math forum I did see an approach where max(f(x),g(x)) = ( f(x)+g(x) + abs(f(x)-g(x)) )/2 and then one need only consider when the abs() changes sign but I blv this is a different case, as my inputs x_i are different for each output.