It depends. From the ABIM Website:
Trainees in the internal medicine research pathway may be admitted to the certification examination in internal medicine in the summer of PGY- 5 after successful completion of four years of training, which must include 24 months of accredited training in internal medicine and 24 months of research training. Documentation that the resident will be in full-time residency training or in a position with 80 percent involvement in mentored research during PGY-5 will be required at the time of application.
Trainees in the subspecialty research pathway must be certified in internal medicine at the time of application to be eligible to apply for certification in a subspecialty. Subspecialty research trainees may be admitted to the certification examination in internal medicine in the summer of PGY-4, as long as two required years of accredited training in internal medicine and one year of accredited subspecialty training have been completed satisfactorily.
So if the PGY-3 year is a clinical year, then you take it summer of PGY-4. If it's a research year, then you take it summer of PGY-5.