-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set cpu affinity and membind for better oob performance #853
Merged
Merged
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
54bc512
set num threads and memory binding for better OOB performance
rbrugaro 5d19b46
clean env var
rbrugaro 37e1022
Merge branch 'huggingface:main' into numa
rbrugaro 9387717
added core and memory binding util for improved performance
rbrugaro 191f772
add example usage in docstring
rbrugaro 1a20674
Merge branch 'huggingface:main' into numa
rbrugaro 2773fe6
change utlity for best oob to support world_size and rank >=1
rbrugaro 7b37c39
Merge branch 'huggingface:main' into numa
rbrugaro fa5526a
fix style
rbrugaro 09ac1ce
fix node_id value to account for rank_id starts at zero
rbrugaro 8b476f8
numa node assignment calculated from local size not from world size
rbrugaro 85ccfc4
reorg imports, moved checks to import_utils, remove prints for logger
rbrugaro 5407359
raise Errors with missing pkg and unsupported OS
rbrugaro 95b65fe
added missng env var to list
rbrugaro 7fb3cb5
Update optimum/intel/utils/modeling_utils.py
IlyasMoutawwakil 3613f69
Update optimum/intel/utils/import_utils.py
IlyasMoutawwakil c825876
Update optimum/intel/utils/import_utils.py
IlyasMoutawwakil 4535927
Merge branch 'main' into numa
IlyasMoutawwakil e658ffc
fix style quality error
rbrugaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,6 @@ | |
from ..utils.import_utils import is_ipex_version, is_torch_version, is_transformers_version | ||
from ..utils.modeling_utils import MULTI_QUERY_ATTN_MODELS, recursive_to_device | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
|
@@ -129,6 +128,21 @@ def ipex_jit_trace(model, task, use_cache): | |
|
||
return trace_model | ||
|
||
def get_int_from_env(env_keys, default): | ||
"""Returns the first positive env value found in the `env_keys` list or the default.""" | ||
for e in env_keys: | ||
val = int(os.environ.get(e, -1)) | ||
if val >= 0: | ||
return val | ||
return default | ||
|
||
def get_number_of_sockets(): | ||
sockets = set() | ||
with open('/proc/cpuinfo') as f: | ||
for line in f: | ||
if line.startswith('physical id'): | ||
sockets.add(line.strip().split()[-1]) | ||
return len(sockets) | ||
|
||
class IPEXModel(OptimizedModel): | ||
auto_model_class = AutoModel | ||
|
@@ -153,6 +167,18 @@ def __init__( | |
else: | ||
self._device = torch.device("cpu") | ||
|
||
import numa | ||
import psutil | ||
n_sockets=get_number_of_sockets() | ||
num_cpu_threads_per_process = int(psutil.cpu_count(logical=False) / n_sockets) | ||
os.environ["OMP_NUM_THREADS"]=str(num_cpu_threads_per_process) | ||
torch.set_num_threads(num_cpu_threads_per_process) | ||
numa.set_affinity(0,range(num_cpu_threads_per_process)) | ||
numa.set_membind([0]) | ||
print("affinity", numa.get_affinity(0)) | ||
print("membind", numa.get_membind()) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also ,if the OMP_NUM_THREADS, membind is already set by external user. should not override the user's configuration. also Tensor Parallel case should be considered as well. |
||
|
||
# CPU only support jit model for now. | ||
if export: | ||
if isinstance(model, torch.jit.RecursiveScriptModule): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add check if the numa package is available