Heat 1 tablespoon of oil in a medium skillet over medium-low heat. Add the sliced onions and cook, stirring often, until they're deeply golden and caramelized. It can take 35 to 40 minutes. Once caramelized, transfer the onions to a bowl to cool.
In the same skillet, add another tablespoon of oil and stir in the chopped garlic. Cook for 1–2 minutes, then add the pumpkin, and rosemary. Season with salt and pepper. Let it cook over low heat, stirring occasionally, just until the pumpkin is tender. You want the cubes to hold their shape. Transfer the pumpkin to a bowl to cool.
Preheat your oven to 400°F. Line a baking sheet with parchment paper and unfold the puff pastry dough. Cut it into rectangles about 2x1 inches. Brush each piece with egg wash and poke a few holes with a fork to help it bake evenly.
Top each piece with a small spoonful of caramelized onions, a sprinkle of gruyere, and a few cubes of pumpkin.
Bake for 10–15 minutes, until the pastry is golden and puffed. Finish each one with a small sprig of fresh rosemary.