In brief, to supplement other answers and remarks: first, I do try to think of "grades" as giving information to students, primarily, so that the "running grade" during the term provides some feedback on my perception of peoples' success. Significantly, I do not imagine, nor position, my courses as "filters" or "challenges", but as informational, provocative, invitations to mathematics that is within my professional scope (after all these years). So I do not want to express (directly or indirectly) "skepticism" that people could (if they wanted, and were interested) follow and assimilate what's going on. That is, "it's not that hard". Sure, nearly anything, even senseless, pointless activities, can be turned into filters or challenges, but... why?
Srsly, if courses are meant to primarily test natural ability (as some of my colleagues have adamantly insisted) then we shouldn't charge tuition, pretending that we're teaching something. That is, if a thing works well, and is do-able, it should be teachable to interested parties.
Then, to the question at hand: if the issue is communication and explanation, probably I'm not grading harshly anyway, and take into consideration everyone's context, not just the undergrads. Duh! That is, my aim is not to declare winners and losers, but to give useful feedback to the people who self-selected to hear what I was talking about. The situation does not demand a competition among them "for limited resources". Certain resources, such as my approval, are not "limited" in any sense that should/could function for external entities who'd wish I'd declare winners and losers.
It does start to be uglier when people are in the room against their will/interests. "Required courses"? Well, ideally, things are required (brush and floss...) because they're "good for you". The imputed virtues are not always easy to see, and are sometimes hijacked for various ideological purposes. Nevertheless, I do try to sway/convert people who're grudgingly present, that the "burden" is actually a "help/opportunity", despite sadly-all-too-common presentations that make everything lugubrious and awful.
To reiterate: sure, I do grade people in different contexts differently, because the grade is an item of communication. Not the only one, in my classes. The central administration does seem to collapse to wanting a single number... but I try to ignore that, and not harm the students who have some curiosity about what I offer to discuss with them.
(So, indeed, as in other answers and comments, the various mechanisms of self-selection present people with a great variety of motivations and interests. Responding to them individually, say with a class of 15-25, is not so terrible at all, and quite interesting, and, I fancy, a good deed. To "rank them" seems on most occasions to be not sane... Or maybe that's just a special case of the insanity of the bureacratic-school pressure to do this. True, many students pre-emptively operate in that context, but I do not take that as a mandate to sink to the same sad level. I.e., it's not that we "don't leave any child behind" by not moving forward, but that we gather them up and do move, etc, blah-blah-blah).
Or, sure, cold mountain-slopes for babies, ... single combat ... :)
Srsly, I do think that in upper-division, much less grad-level, people should not be beat-up grade-wise. They volunteered to be there! Even if they're not so very good at what they'd like to do, "giving a bad grade" is not helping them. The far-subtler issue is how to help a person who wants to do something that they're currently not-so-good-at. Various misunderstandings create fake incompetencies!