Unfortunately, this will only apply to students and beginning faculty at larger institutions. Places with quite a few faculty members and, maybe with quite a few students as well.
But, at such a place, if you look around, you will probably find that there is a lot of collaboration already going on. You want to get connected to some of that in an area that interests you, at least a bit.
At some such places, senior faculty hold weekly seminars that aren't formal, but meet regularly. They will consist of the senior person, a few other faculty of various ranks, and a few students, usually advisees of some of those faculty. They are often organized around the main research interest of the senior person who organized and maintain it. People contribute ideas and discuss papers. Sometimes a member will be asked to make a presentation to the group (say half a dozen or ten) about some paper or some idea of interest. The key is people connected to ideas and to each other.
If you don't find such groups already formed, they may just be too small, with two or three faculty meeting in an office, or even at the coffee table, to discuss what they are working on and asking for advice.
If you don't find even that, it might be possible for you to form such a group, though in this case mostly students. Suppose you can find three or four other students with similar interests. Perhaps you've met them in class. Form a group yourself and go as a group to some faculty member and ask if s/he will "sponsor" you, by taking over the mentorship of your group. Perhaps they can give you some problem of interest for you to study together. Note that nothing formal needs to come from such a group, though it is great if it does. Think of it more as "expanding horizons" than as "goal directed". Before you start on anything serious, make sure you have worked out authorship issues. Don't neglect to be generous in that. In an ideal situation, these people can have a long term research relationship lasting beyond degrees.
If it is impossible to develop local relationships, then it is much harder. Being very social at conferences is a good way. Ask a lot of questions. Have coffee with a lot of people. Collect and distribute a lot of business cards, etc. The actual work of collaboration is a bit easier now with computer communication, but forming a compatible group is still quite difficult.