Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 12 min read How-to mediumAdept

Deploying πŸ€— ViT on Kubernetes with TF Serving

A Vision Transformer from Hugging Face Transformers, exported as a TensorFlow SavedModel, is packaged into a custom TensorFlow Serving Docker image and deployed to a GKE cluster. The walkthrough covers building the image via docker commit with the versioned model directory layout, pushing it to GCR, and writing Deployment, Service (LoadBalancer exposing gRPC 8500 and REST 8501) and HorizontalPodAutoscaler manifests applied with kubectl or Kustomize. It also explains how CPU requests drive HPA scaling decisions and how to tune TF Serving's inter-op and intra-op parallelism flags.

Assumes: Docker basicsKubernetes basicsTensorFlow SavedModel

Related posts

  • Deploying TensorFlow Vision Models in Hugging Face with TF Serving

    Hugging Face mediumAdept

    A Vision Transformer image classifier from Hugging Face Transformers can be served locally with TensorFlow Serving by exporting it as a SavedModel with preprocessing and postprocessing embedded in the graph. A custom serving signature accepts base64-encoded JPEG strings, then decodes, resizes, normalizes and transposes them to channel-first, and returns a class label plus softmax confidence. Building these steps into the model cuts request payload size and avoids training-serving skew. The walkthrough covers launching tensorflow_model_server and querying both the REST endpoint (port 8501) and the gRPC endpoint (port 8500), including how to select a model version.

  • Deploying πŸ€— ViT on Vertex AI

    Hugging Face mediumAdept

    A TensorFlow ViT B/16 SavedModel from πŸ€— Transformers, with base64 image preprocessing and label postprocessing baked into its signature, can be served on Google Cloud Vertex AI in four SDK steps: upload to the Model Registry, create an Endpoint, deploy with machine/accelerator specs and traffic split, then send prediction requests. Code covers ModelServiceClient, EndpointServiceClient and PredictionServiceClient usage and the required {"b64": ...} request payload format. A Locust load test on an n1-standard-8 with one T4 GPU averaged 646 ms latency over about 17k requests, and hourly pricing is roughly $0.44 for the machine plus $0.40 for the T4.

  • My Journey to a serverless transformers pipeline on Google Cloud

    Hugging Face mediumAdept

    A Hugging Face transformers sentiment-analysis pipeline (DistilBERT fine-tuned on SST-2) was deployed as a low-traffic microservice on Google Cloud Run after AI Platform Prediction (beta instability, checkpoint not a pure TensorFlow model) and App Engine (TensorFlow install failure, PyTorch handling only 2 requests per instance) fell short. The final setup is a Flask app served by gunicorn with one worker and one thread in a Docker image, with Cloud Run memory raised to 4 GB because the model needs most of it. Requests take under five seconds including model loading, plus roughly 10 seconds on cold start; loading the model at startup instead of per request would cut both latency and memory. The image is about 1 GB (PyTorch ~700 MB, model ~250 MB), so storage costs roughly €0.10 per GB per month on top of request costs.

  • Deploy Triton Inference Server on Railway

    Railway mediumAdept

    NVIDIA Triton Inference Server can serve CPU-friendly ML models on Railway, with MinIO as an S3-compatible model repository. The walkthrough starts with PyTriton wrapping a simple AddSub model in a Docker image and calling it through the Triton HTTP client. It then moves to plain tritonserver in poll mode, reading a model repository from MinIO so models such as a Python AddSub and a TorchScript ResNet18 load dynamically when uploaded. Config.pbtxt layouts, the required AWS credential environment variables and a client for listing models and running inference are all shown.

  • Hugging Face's TensorFlow Philosophy

    Hugging Face mediumAdept

    Hugging Face's transformers library treats TensorFlow models as first-class Keras citizens: every model is a Keras Model and every layer a Keras Layer, so fit(), compile() and predict() work directly, and models compose into custom hybrids via subclassing. If compile() is called without a loss argument, a sensible default loss is supplied (e.g. masked LM loss that matches BERT's original training), but a user-specified loss overrides it. Labels can now be passed the standard Keras way, and prepare_tf_dataset() streams disk-backed datasets with per-batch padding. XLA via jit_compile=True brings generation and training to roughly JAX-level speed, with the caveat that variable input shapes force recompilation.

The quest for software engineering knowledge.

Look:
Layout: