Skip to content

Commit

Permalink
enable core allocation verification in handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Naman Nandan committed Jun 13, 2023
1 parent a64938c commit ecc5e02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions examples/large_models/inferentia2/inf2_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from abc import ABC

import torch
import torch_neuronx
import transformers
from transformers import AutoTokenizer
from transformers_neuronx.opt.model import OPTForSampling
Expand Down Expand Up @@ -42,6 +43,18 @@ def initialize(self, ctx):

# allocate "tp_degree" number of neuron cores to the worker process
os.environ["NEURON_RT_NUM_CORES"] = str(tp_degree)
try:
num_neuron_cores_available = (
torch_neuronx.xla_impl.data_parallel.device_count()
)
assert num_neuron_cores_available == int(tp_degree)
except (RuntimeError, AssertionError) as error:
raise RuntimeError(
"Required number of neuron cores for tp_degree "
+ str(tp_degree)
+ " are not available: "
+ str(error)
)

torch.manual_seed(seed)
self.tokenizer = AutoTokenizer.from_pretrained(model_name, return_tensors="pt")
Expand Down
4 changes: 2 additions & 2 deletions examples/large_models/inferentia2/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
transformers
torch-neuronx
transformers-neuronx
torch==1.13.1
transformers

0 comments on commit ecc5e02

Please sign in to comment.