Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit c1f89be

Browse files
committed
attempt to deal with missing Linux-only os.sched_getaffinity
Signed-off-by: Luke Nezda <[email protected]>
1 parent e68000f commit c1f89be

File tree

1 file changed

+8
-1
lines changed
  • intel_extension_for_transformers/llm/runtime/graph

1 file changed

+8
-1
lines changed

intel_extension_for_transformers/llm/runtime/graph/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
17+
import multiprocessing
1718
import os
1819

1920
import torch
@@ -132,7 +133,13 @@ def init_from_bin(self, model_type, model_path, **generate_kwargs):
132133
if "threads" not in generate_kwargs:
133134
threads = os.getenv("OMP_NUM_THREADS")
134135
if threads is None:
135-
generate_kwargs["threads"] = len(os.sched_getaffinity(0))
136+
# hack from https://stackoverflow.com/questions/74048135/alternatives-to-os-sched-getaffinity-for-macos
137+
# do we need physical core count instead?
138+
try:
139+
# NOTE: only available on some Unix platforms
140+
generate_kwargs["threads"] = len(os.sched_getaffinity(0))
141+
except AttributeError:
142+
generate_kwargs["threads"] = multiprocessing.cpu_count()
136143
else:
137144
generate_kwargs["threads"] = int(threads)
138145
self.model.init_model(model_path, **generate_kwargs)

0 commit comments

Comments
 (0)