Skip to content

Instantly share code, notes, and snippets.

@kristjan-eljand
Created March 22, 2021 14:01
Show Gist options
  • Save kristjan-eljand/678d7952fff130b972f9f70055e9fbb3 to your computer and use it in GitHub Desktop.
Save kristjan-eljand/678d7952fff130b972f9f70055e9fbb3 to your computer and use it in GitHub Desktop.
GPT2 inference with Ray on 2 cores
ray.init(num_cpus=2, ignore_reinit_error=True)
# Create remote function
@ray.remote
def continue_text(beginning):
text = generator(beginning, max_length=30, num_return_sequences=1)
return text[0]['generated_text']
start = time.time()
# Send continue_text() to multiple cores and gather the results
results = ray.get([continue_text.remote(beginning) for beginning in sentence_beginnings])
print("duration =", time.time() - start)
print(results)
# Output:
# duration = 9.799829721450806
# In Estonia, our main source of energy is from Russian nuclear power plants. But for our new power stations ..
# The main task of the technology scout is finding ways to spot which parts of the code can be used...
# Renewable energy is important because it can provide an energy source for a wide range of applications...
# Electric Vehicles are changing the lives of people. They're becoming more and more likely to be used as vehicles...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment