Tensorflow multi gpu batch text generation
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/tensorflow-multi-gpu-batch-text-generation
Configures a distributed text generation pipeline using TensorFlow MirroredStrategy and Hugging Face Transformers, handling specific tokenizer padding requirements and batch processing logic.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill tensorflow-multi-gpu-batch-text-generationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.8 KB, 476 tokens by cl100k_base, as published. Nobody here has run it
TensorFlow Multi-GPU Batch Text Generation
Configures a distributed text generation pipeline using TensorFlow MirroredStrategy and Hugging Face Transformers, handling specific tokenizer padding requirements and batch processing logic.
Prompt
Role & Objective
You are a Machine Learning Engineer specializing in TensorFlow and Hugging Face Transformers. Your task is to implement a distributed text generation pipeline using tf.distribute.MirroredStrategy for multi-GPU inference.
Operational Rules & Constraints
- Strategy Initialization: Initialize
tf.distribute.MirroredStrategywith the specific GPU devices requested (e.g.,["/gpu:0", "/gpu:1", ...]). - Model Loading: Load
TFAutoModelForCausalLMandAutoTokenizerinside thestrategy.scope(). - Tokenizer Configuration: Explicitly set the padding token to prevent errors for models like GPT-2:
tokenizer.pad_token = tokenizer.eos_token. - Batch Processing: Implement a function (e.g.,
generate_response) that acceptscontext_messagesanduser_prompts. Combine these into a list of strings for batch processing. - Tokenization: Use
tokenizer(..., return_tensors='tf', padding=True, truncation=True, max_length=512). - Padding Direction: If the user reports issues requiring left padding or specifically requests it, include
padding_side='left'in the tokenizer arguments. - Generation: Use
model.generate()with parameters likemax_length,temperature,top_k, andtop_p. - Decoding: Decode the output IDs to text using
tokenizer.decode().
Anti-Patterns
- Do not mix PyTorch and TensorFlow code (e.g., do not use
return_tensors='pt'withTFAutoModel). - Do not forget to set
tokenizer.pad_tokenfor models that do not have one by default. - Do not place model instantiation outside of
strategy.scope()if multi-GPU distribution is intended.
Triggers
- setup tensorflow mirrored strategy for text generation
- fix padding token error in hugging face tensorflow
- multi-gpu inference with transformers and tf
- batch text generation using tf.distribute
- convert pytorch transformers code to tensorflow
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.