I don't have any experience running machine learning apps or using AWS GPU options.
But doing a quick Google Search it looks like you can provision GPUs with ECS outlined in this article: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-gpu.html
It looks like these configurations should be possible to add to Terraform. Like adding a `placement_constraints` to the `ecs_task_definition`: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#placement_constraints
I am uncertain (1) how you would hook your machine learning app to the GPU inside ECS or (2) the cost of running such a service.
Nevertheless, hopefully this points you in the right direction.