keras/src/trainers/compile_utils.py/CompileLoss/_flatten_y
class CompileLoss:    def _flatten_y(self, y):
        if isinstance(y, dict) and self.output_names:
            result = []
            for name in self.output_names:
                if name in y:
                    result.append(y[name])
            return result
        return tree.flatten(y)