So as we know that every mammal needs atleast some amount of sleep or a resting period to perform cognitive functions through out the their day, this however can vary drastically based on the mammal's habits, such as if they are herbivores or carnivores, their place in the food chain (if they are a predator or prey), their habitat, their body size etc.
Starting with humans (to set a point of reference), we ideally need 7-8 hours of sleep in a day. Getting less or more sleep than this ideal can have a lot of different consequences (ranging from feeling tired and foggy to heart conditions and even death). A study performed by a group of researchers to find out the ideal sleep duration in humans showed that just after 14 days the people getting 8 hrs of sleep showed average cognition and a healthy mind, those getting 6 hrs of sleep per day for 14 days showed a similar reaction time to a person with blood alcohol level of 0.1% (which is considered legally drunk in most places), and the group getting 4 hrs of sleep per day for 14 days were tending to fall asleep while performing basic cognitive tasks. This show exactly how important sleep actually is.
Now moving on to some other mammals.
A very commonly discussed example is that of giraffes. Giraffes generally exhibit a cycle of just 2 hrs of sleep per day, and some days they just tend to not sleep at all. A lot of factors contribute to their sleeping habits. Firstly since they are herbivores, and primarily feed on leaves, they need to eat a lot of leaves to get enough energy for their body, having a large body also contributes to this. So, they tend spend about 75% of their day just eating. Other than this since giraffes are prey and a good source of food for lions, they need to stay awake and alert at all times. Sometimes they will take little 10 min long powernaps (this is when they are the most vulnerable, so they don't do it often).
Carnivores however (like lions) sleep a lot more, due to their diets (just like us they feel sleepy after eating) and also since they are minimal risk of being attacked as they are on top of the food chain.
Next lets talk about some sea mammals, they have a hard time trying to snooze because of them being underwater.
Dolphins have very interesting sleep habits as they have to actively come to the surface to breath. Dolphins practice something called "unihemispheric slow-wave sleep", this basically means that they only rest one hemisphere(or side) of their brain at a time(so that they can be awake and asleep at the same time), this is what uni(one) hemispheric(side) means. Slow-wave sleep refers to the deepest phase of sleep, meaning when the one hemisphere is sleeping it is out like a lightbulb. This way dolphins tend to sleep a lot, they have sleep cycle of about 8 hours of sleep a day (resting each hemisphere for 2 hrs at a time). So the dolphins you saw at sea world last year could have been half asleep (literally).
Some birds also practice this uni hemispheric sleep.
I can't think of any animals that sleep "as needed" because activities like sleep and wake are rhythmic and control various hormones and metabolic reactions of the body, this is primarily why we have sleep patterns so that other activities in the body can be done in a habitual manner. This is maintained by our "biological clock", which is the term used to define the natural sleep-wake cycle in animals. The biological clock is regulated by a hormone known as "melatonin".
So yeah, these were some examples I remembered off the top of my head. I have provided some links to why sleep is important, ideal sleep habits in humans and other mammals and some other stuff for further reading.
Hope this answer helped you understand sleep better.
Sleep: a good investment in health and safety - https://pubmed.ncbi.nlm.nih.gov/19042703/
The Transcriptional Repressor DEC2 Regulates Sleep Length in Mammals - https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2884988/
How Animals Sleep - https://www.sleepfoundation.org/animals-and-sleep#:~:text=Giraffes%20need%20less%20sleep%20than,of%2030%20minutes%20per%20day.
Melatonin: what you need to know - https://www.nccih.nih.gov/health/melatonin-what-you-need-to-know
This is an animated video series explaining sleep in different animals (highly recommend watching this):
Part 1 - https://www.youtube.com/watch?v=HA1EPRbMMQU
Part 2 - https://www.youtube.com/watch?v=EJzUKsJ-uhA
Part 3 - https://www.youtube.com/watch?v=S4uX2KeEifM
Rare Genetic Mutation Lets Some People Function with Less Sleep (this might also interest you) - https://www.scientificamerican.com/article/genetic-mutation-sleep-less/