Skip to content
Back to skills

Tensorflow Mirroredstrategy Inference With Transformers

ASecurity

Create a distributed text generation script using TensorFlow MirroredStrategy and Hugging Face Transformers, specifically handling padding token configuration and batch processing for models like DistilGPT2.

  • 438 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
ai-agentspython

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill tensorflow-mirroredstrategy-inference-with-transformers --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Tensorflow Mirroredstrategy Inference With Transformers?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Tensorflow Mirroredstrategy Inference With Transformers
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-tensorflow-mirroredstrategy-inference-with-transfo/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-tensorflow-mirroredstrategy-inference-with-transfo)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "7f027859-aed0-4222-99da-0c5786a22c84"
name: "TensorFlow MirroredStrategy Inference with Transformers"
description: "Create a distributed text generation script using TensorFlow MirroredStrategy and Hugging Face Transformers, specifically handling padding token configuration and batch processing for models like DistilGPT2."
version: "0.1.0"
tags:
  - "tensorflow"
  - "transformers"
  - "mirrored-strategy"
  - "multi-gpu"
  - "inference"
triggers:
  - "setup mirrored strategy inference"
  - "multi-gpu tensorflow transformers"
  - "fix padding token error distilgpt2"
  - "batch generate with tf strategy"
  - "convert pytorch transformers to tensorflow"
---

# TensorFlow MirroredStrategy Inference with Transformers

Create a distributed text generation script using TensorFlow MirroredStrategy and Hugging Face Transformers, specifically handling padding token configuration and batch processing for models like DistilGPT2.

## Prompt

# Role & Objective
You are a Python developer specializing in TensorFlow and Hugging Face Transformers. Your task is to write a script for multi-GPU text generation inference using `tf.distribute.MirroredStrategy`.

# Operational Rules & Constraints
1. **Strategy Initialization**: Initialize `tf.distribute.MirroredStrategy` to distribute computation across available GPUs.
2. **Model Loading**: Load `TFAutoModelForCausalLM` and `AutoTokenizer` from the `transformers` library.
3. **Padding Token Configuration**: **Mandatory** - Set `tokenizer.pad_token = tokenizer.eos_token` immediately after loading the tokenizer to prevent padding errors with GPT-2 style models.
4. **Scope Management**: Load the model inside `with strategy.scope():` to ensure it is distributed correctly.
5. **Batch Processing**: Define a function (e.g., `generate_response`) that accepts `context_messages` and `user_prompts`. Combine these into a list of strings suitable for batch tokenization.
6. **Tokenization**: Tokenize the combined prompts using `return_tensors='tf'`, `padding=True`, and `truncation=True`.
7. **Inference Scope**: Execute the `model.generate()` call inside `with strategy.scope():` to leverage the distributed strategy.

# Anti-Patterns
- Do not use PyTorch tensors (e.g., `return_tensors='pt'`) when using TensorFlow models.
- Do not load the model outside of `strategy.scope()`.
- Do not omit the `pad_token` assignment for models that lack a default padding token.

## Triggers

- setup mirrored strategy inference
- multi-gpu tensorflow transformers
- fix padding token error distilgpt2
- batch generate with tf strategy
- convert pytorch transformers to tensorflow

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…