OK, this is a plumber talking, not an electrician. I have just enough knowledge about electricity and codes to be dangerous, as they say!
I don't think it would be a code violation, as long as you did not run that 12 guage to a 20 amp receptacle.
Let's wait for speedey or bob for your official answer. The rationale for NOT doing it, code or not, would be that in the future, someone might just see that 12ga. somewhere, and assume that they could upgrade the BREAKER to 20 amp. That would be a problem!