Caramelize the onions (skip this step if you're using caramelized onion relish). Heat 1 tablespoon of olive oil in a large skillet over medium heat. Add the sliced onions, 1 teaspoon of salt, and 1 teaspoon of balsamic vinegar, then cook, stirring often, until they're soft and deeply golden. This will take at least 25 minutes. Set aside to cool slightly.
Heat your oven and prepare your muffin pan. Set your oven to 375°F (180°C fan) and grease a 24 cup mini muffin pan with butter or oil (oil spray makes this easy).
Prepare the phyllo (filo). Lay one sheet of pastry on a wooden board or flat surface. Brush all over with olive oil, then lay another sheet of pastry on top. Brush with olive oil again, then lay the third sheet of filo on top. Keep your pastry covered with a damp kitchen towel while you're working to prevent it from drying out. Slice the pastry into small squares. I like to slice a test square first before cutting them all, just to make sure they are the right size for the muffin pan.
Assemble the bites.Gently press the pastry squares into your muffin pan to form little cups; they should easily fold in. Spoon a little of the caramelized onions (or relish) into each cup. Add a few pieces of chopped bacon, then top with a cube of Gruyère. Bake the cups. Transfer the muffin pan to the oven, and bake for about 10 to 12 minutes, until the pastry looks golden and glorious, the bacon is cooked through and crispy, and the cheese is bubbling.
Garnish and serve. Remove the pan from the oven, and let the cups cool slightly in the pan before gently removing them (they should pop out easily). Arrange them on a serving platter, then sprinkle with the fresh rosemary. Serve warm or at room temperature.