Download data.json from codimeow/cAI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 143 kB
-
https://huggingface.co/codimeow/cAI-dataset/resolve/main/data.json
- Command line
-
hf download hf://codimeow/cAI-dataset/data.json
-
curl -L -o data.json https://huggingface.co/codimeow/cAI-dataset/resolve/main/data.json
143 kB
| [ | |
| { | |
| "url": "https://github.com/tensorflow/tensorflow", | |
| "files": [ | |
| { | |
| "name": "configure.py", | |
| "content": "# Copyright 2017 The TensorFlow Authors. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n# ==============================================================================\n\"\"\"configure script to get build parameters from user.\"\"\"\n\nimport argparse\nimport errno\nimport json\nimport os\nimport platform\nimport re\nimport shutil\nimport subprocess\nimport sys\n\n\n_DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,7.0'\n\n_SUPPORTED_ANDROID_NDK_VERSIONS = [19, 20, 21, 25]\n\n_DEFAULT_PROMPT_ASK_ATTEMPTS = 10\n\n_TF_BAZELRC_FILENAME = '.tf_configure.bazelrc'\n_TF_WORKSPACE_ROOT = ''\n_TF_BAZELRC = ''\n_TF_CURRENT_BAZEL_VERSION = None\n\nNCCL_LIB_PATHS = [\n 'lib64/', 'lib/powerpc64le-linux-gnu/', 'lib/x86_64-linux-gnu/', ''\n]\n\n# List of files to configure when building Bazel on Apple platforms.\nAPPLE_BAZEL_FILES = [\n 'tensorflow/lite/ios/BUILD', 'tensorflow/lite/objc/BUILD',\n 'tensorflow/lite/swift/BUILD',\n 'tensorflow/lite/tools/benchmark/experimental/ios/BUILD'\n]\n\n# List of files to move when building for iOS.\nIOS_FILES = [\n 'tensorflow/lite/objc/TensorFlowLiteObjC.podspec',\n 'tensorflow/lite/swift/TensorFlowLiteSwift.podspec',\n]\n\n\nclass UserInputError(Exception):\n pass\n\n\ndef is_windows():\n return platform.system() == 'Windows'\n\n\ndef is_linux():\n return platform.system() == 'Linux'\n\n\ndef is_macos():\n return platform.system() == 'Darwin'\n\n\ndef is_ppc64le():\n return platform.machine() == 'ppc64le'\n\n\ndef is_s390x():\n return platform.machine() == 's390x'\n\n\ndef is_cygwin():\n return platform.system().startswith('CYGWIN_NT')\n\n\ndef get_input(question):\n try:\n try:\n answer = raw_input(question)\n except NameError:\n answer = input(question) # pylint: disable=bad-builtin\n except EOFError:\n answer = ''\n return answer\n\n\ndef symlink_force(target, link_name):\n \"\"\"Force symlink, equivalent of 'ln -sf'.\n\n Args:\n target: items to link to.\n link_name: name of the link.\n \"\"\"\n try:\n os.symlink(target, link_name)\n except OSError as e:\n if e.errno == errno.EEXIST:\n os.remove(link_name)\n os.symlink(target, link_name)\n else:\n raise e\n\n\ndef write_to_bazelrc(line):\n with open(_TF_BAZELRC, 'a') as f:\n f.write(line + '\\n')\n\n\ndef write_action_env_to_bazelrc(var_name, var):\n write_to_bazelrc('build --action_env {}=\"{}\"'.format(var_name, str(var)))\n\n\ndef write_repo_env_to_bazelrc(config_name, var_name, var):\n write_to_bazelrc(\n 'build:{} --repo_env {}=\"{}\"'.format(config_name, var_name, str(var))\n )\n\n\ndef run_shell(cmd, allow_non_zero=False, stderr=None):\n if stderr is None:\n stderr = sys.stdout\n if allow_non_zero:\n try:\n output = subprocess.check_output(cmd, stderr=stderr)\n except subprocess.CalledProcessError as e:\n output = e.output\n else:\n output = subprocess.check_output(cmd, stderr=stderr)\n return output.decode('UTF-8').strip()\n\n\ndef cygpath(path):\n \"\"\"Convert path from posix to windows.\"\"\"\n return os.path.abspath(path).replace('\\\\', '/')\n\n\ndef get_python_path(environ_cp, python_bin_path):\n \"\"\"Get the python site package paths.\"\"\"\n python_paths = []\n if environ_cp.get('PYTHONPATH'):\n python_paths = environ_cp.get('PYTHONPATH').split(':')\n try:\n stderr = open(os.devnull, 'wb')\n library_paths = run_shell([\n python_bin_path, '-c',\n 'import site; print(\"\\\\n\".join(site.getsitepackages()))'\n ],\n stderr=stderr).split('\\n')\n except subprocess.CalledProcessError:\n library_paths = [\n run_shell([\n python_bin_path,\n '-c',\n 'import sysconfig;print(sysconfig.get_path(\"purelib\")',\n ])\n ]\n\n all_paths = set(python_paths + library_paths)\n # Sort set so order is deterministic\n all_paths = sorted(all_paths)\n\n paths = []\n for path in all_paths:\n if os.path.isdir(path):\n paths.append(path)\n return paths\n\n\ndef get_python_major_version(python_bin_path):\n \"\"\"Get the python major version.\"\"\"\n return run_shell([python_bin_path, '-c', 'import sys; print(sys.version[0])'])\n\n\ndef setup_python(environ_cp):\n \"\"\"Setup python related env variables.\"\"\"\n # Get PYTHON_BIN_PATH, default is the current running python.\n default_python_bin_path = sys.executable\n ask_python_bin_path = ('Please specify the location of python. [Default is '\n '{}]: ').format(default_python_bin_path)\n while True:\n python_bin_path = get_from_env_or_user_or_default(environ_cp,\n 'PYTHON_BIN_PATH',\n ask_python_bin_path,\n default_python_bin_path)\n # Check if the path is valid\n if os.path.isfile(python_bin_path) and os.access(python_bin_path, os.X_OK):\n break\n elif not os.path.exists(python_bin_path):\n print('Invalid python path: {} cannot be found.'.format(python_bin_path))\n else:\n print('{} is not executable. Is it the python binary?'.format(\n python_bin_path))\n environ_cp['PYTHON_BIN_PATH'] = ''\n\n # Convert python path to Windows style before checking lib and version\n if is_windows() or is_cygwin():\n python_bin_path = cygpath(python_bin_path)\n\n # Get PYTHON_LIB_PATH\n python_lib_path = environ_cp.get('PYTHON_LIB_PATH')\n if not python_lib_path:\n python_lib_paths = get_python_path(environ_cp, python_bin_path)\n if environ_cp.get('USE_DEFAULT_PYTHON_LIB_PATH') == '1':\n python_lib_path = python_lib_paths[0]\n else:\n print('Found possible Python library paths:\\n %s' %\n '\\n '.join(python_lib_paths))\n default_python_lib_path = python_lib_paths[0]\n python_lib_path = get_input(\n 'Please input the desired Python library path to use. '\n 'Default is [{}]\\n'.format(python_lib_paths[0]))\n if not python_lib_path:\n python_lib_path = default_python_lib_path\n environ_cp['PYTHON_LIB_PATH'] = python_lib_path\n\n python_major_version = get_python_major_version(python_bin_path)\n if python_major_version == '2':\n write_to_bazelrc('build --host_force_python=PY2')\n\n # Convert python path to Windows style before writing into bazel.rc\n if is_windows() or is_cygwin():\n python_lib_path = cygpath(python_lib_path)\n\n # Set-up env variables used by python_configure.bzl\n write_action_env_to_bazelrc('PYTHON_BIN_PATH', python_bin_path)\n write_action_env_to_bazelrc('PYTHON_LIB_PATH', python_lib_path)\n write_to_bazelrc('build --python_path=\\\"{}\"'.format(python_bin_path))\n environ_cp['PYTHON_BIN_PATH'] = python_bin_path\n\n # If chosen python_lib_path is from a path specified in the PYTHONPATH\n # variable, need to tell bazel to include PYTHONPATH\n if environ_cp.get('PYTHONPATH'):\n python_paths = environ_cp.get('PYTHONPATH').split(':')\n if python_lib_path in python_paths:\n write_action_env_to_bazelrc('PYTHONPATH', environ_cp.get('PYTHONPATH'))\n\n # Write tools/python_bin_path.sh\n with open(\n os.path.join(_TF_WORKSPACE_ROOT, 'tools', 'python_bin_path.sh'),\n 'w') as f:\n f.write('export PYTHON_BIN_PATH=\"{}\"'.format(python_bin_path))\n\n\ndef reset_tf_configure_bazelrc():\n \"\"\"Reset file that contains customized config settings.\"\"\"\n open(_TF_BAZELRC, 'w').close()\n\n\ndef cleanup_makefile():\n \"\"\"Delete any leftover BUILD files from the Makefile build.\n\n These files could interfere with Bazel parsing.\n \"\"\"\n makefile_download_dir = os.path.join(_TF_WORKSPACE_ROOT, 'tensorflow',\n 'contrib', 'makefile', 'downloads')\n if os.path.isdir(makefile_download_dir):\n for root, _, filenames in os.walk(makefile_download_dir):\n for f in filenames:\n if f.endswith('BUILD'):\n os.remove(os.path.join(root, f))\n\n\ndef get_var(environ_cp,\n var_name,\n query_item,\n enabled_by_default,\n question=None,\n yes_reply=None,\n no_reply=None):\n \"\"\"Get boolean input from user.\n\n If var_name is not set in env, ask user to enable query_item or not. If the\n response is empty, use the default.\n\n Args:\n environ_cp: copy of the os.environ.\n var_name: string for name of environment variable, e.g. \"TF_NEED_CUDA\".\n query_item: string for feature related to the variable, e.g. \"CUDA for\n Nvidia GPUs\".\n enabled_by_default: boolean for default behavior.\n question: optional string for how to ask for user input.\n yes_reply: optional string for reply when feature is enabled.\n no_reply: optional string for reply when feature is disabled.\n\n Returns:\n boolean value of the variable.\n\n Raises:\n UserInputError: if an environment variable is set, but it cannot be\n interpreted as a boolean indicator, assume that the user has made a\n scripting error, and will continue to provide invalid input.\n Raise the error to avoid infinitely looping.\n \"\"\"\n if not question:\n question = 'Do you wish to build TensorFlow with {} support?'.format(\n query_item)\n if not yes_reply:\n yes_reply = '{} support will be enabled for TensorFlow.'.format(query_item)\n if not no_reply:\n no_reply = 'No {}'.format(yes_reply)\n\n yes_reply += '\\n'\n no_reply += '\\n'\n\n if enabled_by_default:\n question += ' [Y/n]: '\n else:\n question += ' [y/N]: '\n\n var = environ_cp.get(var_name)\n if var is not None:\n var_content = var.strip().lower()\n true_strings = ('1', 't', 'true', 'y', 'yes')\n false_strings = ('0', 'f', 'false', 'n', 'no')\n if var_content in true_strings:\n var = True\n elif var_content in false_strings:\n var = False\n else:\n raise UserInputError(\n 'Environment variable %s must be set as a boolean indicator.\\n'\n 'The following are accepted as TRUE : %s.\\n'\n 'The following are accepted as FALSE: %s.\\n'\n 'Current value is %s.' %\n (var_name, ', '.join(true_strings), ', '.join(false_strings), var))\n\n while var is None:\n user_input_origin = get_input(question)\n user_input = user_input_origin.strip().lower()\n if user_input == 'y':\n print(yes_reply)\n var = True\n elif user_input == 'n':\n print(no_reply)\n var = False\n elif not user_input:\n if enabled_by_default:\n print(yes_reply)\n var = True\n else:\n print(no_reply)\n var = False\n else:\n print('Invalid selection: {}'.format(user_input_origin))\n return var\n\n\ndef set_action_env_var(environ_cp,\n var_name,\n query_item,\n enabled_by_default,\n question=None,\n yes_reply=None,\n no_reply=None,\n bazel_config_name=None):\n \"\"\"Set boolean action_env variable.\n\n Ask user if query_item will be enabled. Default is used if no input is given.\n Set environment variable and write to .bazelrc.\n\n Args:\n environ_cp: copy of the os.environ.\n var_name: string for name of environment variable, e.g. \"TF_NEED_CUDA\".\n query_item: string for feature related to the variable, e.g. \"CUDA for\n Nvidia GPUs\".\n enabled_by_default: boolean for default behavior.\n question: optional string for how to ask for user input.\n yes_reply: optional string for reply when feature is enabled.\n no_reply: optional string for reply when feature is disabled.\n bazel_config_name: adding config to .bazelrc instead of action_env.\n \"\"\"\n var = int(\n get_var(environ_cp, var_name, query_item, enabled_by_default, question,\n yes_reply, no_reply))\n\n if not bazel_config_name:\n write_action_env_to_bazelrc(var_name, var)\n elif var:\n write_to_bazelrc('build --config=%s' % bazel_config_name)\n environ_cp[var_name] = str(var)\n\n\ndef convert_version_to_int(version):\n \"\"\"Convert a version number to a integer that can be used to compare.\n\n Version strings of the form X.YZ and X.Y.Z-xxxxx are supported. The\n 'xxxxx' part, for instance 'homebrew' on OS/X, is ignored.\n\n Args:\n version: a version to be converted\n\n Returns:\n An integer if converted successfully, otherwise return None.\n \"\"\"\n version = version.split('-')[0]\n version_segments = version.split('.')\n # Treat \"0.24\" as \"0.24.0\"\n if len(version_segments) == 2:\n version_segments.append('0')\n for seg in version_segments:\n if not seg.isdigit():\n return None\n\n version_str = ''.join(['%03d' % int(seg) for seg in version_segments])\n return int(version_str)\n\n\ndef retrieve_bazel_version():\n \"\"\"Retrieve installed bazel version (or bazelisk).\n\n Returns:\n The bazel version detected.\n \"\"\"\n bazel_executable = shutil.which('bazel')\n if bazel_executable is None:\n bazel_executable = shutil.which('bazelisk')\n if bazel_executable is None:\n print('Cannot find bazel. Please install bazel/bazelisk.')\n sys.exit(1)\n\n stderr = open(os.devnull, 'wb')\n curr_version = run_shell([bazel_executable, '--version'],\n allow_non_zero=True,\n stderr=stderr)\n if curr_version.startswith('bazel '):\n curr_version = curr_version.split('bazel ')[1]\n\n curr_version_int = convert_version_to_int(curr_version)\n\n # Check if current bazel version can be detected properly.\n if not curr_version_int:\n print('WARNING: current bazel installation is not a release version.')\n return curr_version\n\n print('You have bazel %s installed.' % curr_version)\n return curr_version\n\n\ndef set_cc_opt_flags(environ_cp):\n \"\"\"Set up architecture-dependent optimization flags.\n\n Also append CC optimization flags to bazel.rc..\n\n Args:\n environ_cp: copy of the os.environ.\n \"\"\"\n if is_ppc64le():\n # gcc on ppc64le does not support -march, use mcpu instead\n default_cc_opt_flags = '-mcpu=native'\n elif is_windows():\n default_cc_opt_flags = '/arch:AVX'\n else:\n # On all other platforms, no longer use `-march=native` as this can result\n # in instructions that are too modern being generated. Users that want\n # maximum performance should compile TF in their environment and can pass\n # `-march=native` there.\n # See https://github.com/tensorflow/tensorflow/issues/45744 and duplicates\n default_cc_opt_flags = '-Wno-sign-compare'\n question = ('Please specify optimization flags to use during compilation when'\n ' bazel option \"--config=opt\" is specified [Default is %s]: '\n ) % default_cc_opt_flags\n cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS',\n question, default_cc_opt_flags)\n for opt in cc_opt_flags.split():\n write_to_bazelrc('build:opt --copt=%s' % opt)\n write_to_bazelrc('build:opt --host_copt=%s' % opt)\n\n\ndef set_tf_cuda_clang(environ_cp):\n \"\"\"set TF_CUDA_CLANG action_env.\n\n Args:\n environ_cp: copy of the os.environ.\n \"\"\"\n question = 'Do you want to use clang as CUDA compiler?'\n yes_reply = 'Clang will be used as CUDA compiler.'\n no_reply = 'nvcc will be used as CUDA compiler.'\n set_action_env_var(\n environ_cp,\n 'TF_CUDA_CLANG',\n None,\n True,\n question=question,\n yes_reply=yes_reply,\n no_reply=no_reply,\n bazel_config_name='cuda_clang',\n )\n\n\ndef set_tf_download_clang(environ_cp):\n \"\"\"Set TF_DOWNLOAD_CLANG action_env.\"\"\"\n question = 'Do you wish to download a fresh release of clang? (Experimental)'\n yes_reply = 'Clang will be downloaded and used to compile tensorflow.'\n no_reply = 'Clang will not be downloaded.'\n set_action_env_var(\n environ_cp,\n 'TF_DOWNLOAD_CLANG',\n None,\n False,\n question=question,\n yes_reply=yes_reply,\n no_reply=no_reply,\n bazel_config_name='download_clang')\n\n\ndef get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var,\n var_default):\n \"\"\"Get var_name either from env, or user or default.\n\n If var_name has been set as environment variable, use the preset value, else\n ask for user input. If no input is provided, the default is used.\n\n Args:\n environ_cp: copy of the os.environ.\n var_name: string for name of environment variable, e.g. \"TF_NEED_CUDA\".\n ask_for_var: string for how to ask for user input.\n var_default: default value string.\n\n Returns:\n string value for var_name\n \"\"\"\n var = environ_cp.get(var_name)\n if not var:\n var = get_input(ask_for_var)\n print('\\n')\n if not var:\n var = var_default\n return var\n\n\ndef prompt_loop_or_load_from_env(environ_cp,\n var_name,\n var_default,\n ask_for_var,\n check_success,\n error_msg,\n suppress_default_error=False,\n resolve_symlinks=False,\n n_ask_attempts=_DEFAULT_PROMPT_ASK_ATTEMPTS):\n \"\"\"Loop over user prompts for an ENV param until receiving a valid response.\n\n For the env param var_name, read from the environment or verify user input\n until receiving valid input. When done, set var_name in the environ_cp to its\n new value.\n\n Args:\n environ_cp: (Dict) copy of the os.environ.\n var_name: (String) string for name of environment variable, e.g. \"TF_MYVAR\".\n var_default: (String) default value string.\n ask_for_var: (String) string for how to ask for user input.\n check_success: (Function) function that takes one argument and returns a\n boolean. Should return True if the value provided is considered valid. May\n contain a complex error message if error_msg does not provide enough\n information. In that case, set suppress_default_error to True.\n error_msg: (String) String with one and only one '%s'. Formatted with each\n invalid response upon check_success(input) failure.\n suppress_default_error: (Bool) Suppress the above error message in favor of\n one from the check_success function.\n resolve_symlinks: (Bool) Translate symbolic links into the real filepath.\n n_ask_attempts: (Integer) Number of times to query for valid input before\n raising an error and quitting.\n\n Returns:\n [String] The value of var_name after querying for input.\n\n Raises:\n UserInputError: if a query has been attempted n_ask_attempts times without\n success, assume that the user has made a scripting error, and will\n continue to provide invalid input. Raise the error to avoid infinitely\n looping.\n \"\"\"\n default = environ_cp.get(var_name) or var_default\n full_query = '%s [Default is %s]: ' % (\n ask_for_var,\n default,\n )\n\n for _ in range(n_ask_attempts):\n val = get_from_env_or_user_or_default(environ_cp, var_name, full_query,\n default)\n if check_success(val):\n break\n if not suppress_default_error:\n print(error_msg % val)\n environ_cp[var_name] = ''\n else:\n raise UserInputError('Invalid %s setting was provided %d times in a row. '\n 'Assuming to be a scripting mistake.' %\n (var_name, n_ask_attempts))\n\n if resolve_symlinks:\n val = os.path.realpath(val)\n environ_cp[var_name] = val\n return val\n\n\ndef set_clang_cuda_compiler_path(environ_cp):\n \"\"\"Set CLANG_CUDA_COMPILER_PATH.\"\"\"\n # Upon clang 19 drop the check for 16\n default_clang_path = '/usr/lib/llvm-18/bin/clang'\n if not os.path.exists(default_clang_path):\n default_clang_path = '/usr/lib/llvm-17/bin/clang'\n if not os.path.exists(default_clang_path):\n default_clang_path = '/usr/lib/llvm-16/bin/clang'\n if not os.path.exists(default_clang_path):\n default_clang_path = shutil.which('clang') or ''\n\n clang_cuda_compiler_path = prompt_loop_or_load_from_env(\n environ_cp,\n var_name='CLANG_CUDA_COMPILER_PATH',\n var_default=default_clang_path,\n ask_for_var='Please specify clang path that to be used as host compiler.',\n check_success=os.path.exists,\n resolve_symlinks=True,\n error_msg='Invalid clang path. %s cannot be found.',\n )\n\n # Set CLANG_CUDA_COMPILER_PATH\n environ_cp['CLANG_CUDA_COMPILER_PATH'] = clang_cuda_compiler_path\n write_action_env_to_bazelrc('CLANG_CUDA_COMPILER_PATH',\n clang_cuda_compiler_path)\n return clang_cuda_compiler_path\n\n\ndef create_android_ndk_rule(environ_cp):\n \"\"\"Set ANDROID_NDK_HOME and write Android NDK WORKSPACE rule.\"\"\"\n if is_windows() or is_cygwin():\n default_ndk_path = cygpath('%s/Android/Sdk/ndk-bundle' %\n environ_cp['APPDATA'])\n elif is_macos():\n default_ndk_path = '%s/library/Android/Sdk/ndk-bundle' % environ_cp['HOME']\n else:\n default_ndk_path = '%s/Android/Sdk/ndk-bundle' % environ_cp['HOME']\n\n def valid_ndk_path(path):\n return (os.path.exists(path) and\n os.path.exists(os.path.join(path, 'source.properties')))\n\n android_ndk_home_path = prompt_loop_or_load_from_env(\n environ_cp,\n var_name='ANDROID_NDK_HOME',\n var_default=default_ndk_path,\n ask_for_var='Please specify the home path of the Android NDK to use.',\n check_success=valid_ndk_path,\n error_msg=('The path %s or its child file \"source.properties\" '\n 'does not exist.'))\n write_action_env_to_bazelrc('ANDROID_NDK_HOME', android_ndk_home_path)\n write_action_env_to_bazelrc(\n 'ANDROID_NDK_API_LEVEL',\n get_ndk_api_level(environ_cp, android_ndk_home_path))\n\n\ndef create_android_sdk_rule(environ_cp):\n \"\"\"Set Android variables and write Android SDK WORKSPACE rule.\"\"\"\n if is_windows() or is_cygwin():\n default_sdk_path = cygpath('%s/Android/Sdk' % environ_cp['APPDATA'])\n elif is_macos():\n default_sdk_path = '%s/library/Android/Sdk' % environ_cp['HOME']\n else:\n default_sdk_path = '%s/Android/Sdk' % environ_cp['HOME']\n\n def valid_sdk_path(path):\n return (os.path.exists(path) and\n os.path.exists(os.path.join(path, 'platforms')) and\n os.path.exists(os.path.join(path, 'build-tools')))\n\n android_sdk_home_path = prompt_loop_or_load_from_env(\n environ_cp,\n var_name='ANDROID_SDK_HOME',\n var_default=default_sdk_path,\n ask_for_var='Please specify the home path of the Android SDK to use.',\n check_success=valid_sdk_path,\n error_msg=('Either %s does not exist, or it does not contain the '\n 'subdirectories \"platforms\" and \"build-tools\".'))\n\n platforms = os.path.join(android_sdk_home_path, 'platforms')\n api_levels = sorted(os.listdir(platforms))\n api_levels = [x.replace('android-', '') for x in api_levels]\n\n def valid_api_level(api_level):\n return os.path.exists(\n os.path.join(android_sdk_home_path, 'platforms',\n 'android-' + api_level))\n\n android_api_level = prompt_loop_or_load_from_env(\n environ_cp,\n var_name='ANDROID_API_LEVEL',\n var_default=api_levels[-1],\n ask_for_var=('Please specify the Android SDK API level to use. '\n '[Available levels: %s]') % api_levels,\n check_success=valid_api_level,\n error_msg='Android-%s is not present in the SDK path.')\n\n build_tools = os.path.join(android_sdk_home_path, 'build-tools')\n versions = sorted(os.listdir(build_tools))\n\n def valid_build_tools(version):\n return os.path.exists(\n os.path.join(android_sdk_home_path, 'build-tools', version))\n\n android_build_tools_version = prompt_loop_or_load_from_env(\n environ_cp,\n var_name='ANDROID_BUILD_TOOLS_VERSION',\n var_default=versions[-1],\n ask_for_var=('Please specify an Android build tools version to use. '\n '[Available versions: %s]') % versions,\n check_success=valid_build_tools,\n error_msg=('The selected SDK does not have build-tools version %s '\n 'available.'))\n\n write_action_env_to_bazelrc('ANDROID_BUILD_TOOLS_VERSION',\n android_build_tools_version)\n write_action_env_to_bazelrc('ANDROID_SDK_API_LEVEL', android_api_level)\n write_action_env_to_bazelrc('ANDROID_SDK_HOME', android_sdk_home_path)\n\n\ndef get_ndk_api_level(environ_cp, android_ndk_home_path):\n \"\"\"Gets the appropriate NDK API level to use for the provided Android NDK path.\n \"\"\"\n\n # First check to see if we're using a blessed version of the NDK.\n properties_path = '%s/source.properties' % android_ndk_home_path\n if is_windows() or is_cygwin():\n properties_path = cygpath(properties_path)\n with open(properties_path, 'r') as f:\n filedata = f.read()\n\n revision = re.search(r'Pkg.Revision = (\\d+)', filedata)\n if revision:\n ndk_version = revision.group(1)\n else:\n raise Exception('Unable to parse NDK revision.')\n if int(ndk_version) not in _SUPPORTED_ANDROID_NDK_VERSIONS:\n print('WARNING: The NDK version in %s is %s, which is not '\n 'supported by Bazel (officially supported versions: %s). Please use '\n 'another version. Compiling Android targets may result in confusing '\n 'errors.\\n' %\n (android_ndk_home_path, ndk_version, _SUPPORTED_ANDROID_NDK_VERSIONS))\n write_action_env_to_bazelrc('ANDROID_NDK_VERSION', ndk_version)\n\n # Now grab the NDK API level to use. Note that this is different from the\n # SDK API level, as the NDK API level is effectively the *min* target SDK\n # version.\n meta = open(os.path.join(android_ndk_home_path, 'meta/platforms.json'))\n platforms = json.load(meta)\n meta.close()\n aliases = platforms['aliases']\n api_levels = sorted(list(set([aliases[i] for i in aliases])))\n\n android_ndk_api_level = prompt_loop_or_load_from_env(\n environ_cp,\n var_name='ANDROID_NDK_API_LEVEL',\n var_default='21', # 21 is required for ARM64 support.\n ask_for_var=(\n 'Please specify the (min) Android NDK API level to use. '\n '[Available levels: %s]'\n )\n % api_levels,\n check_success=(lambda *_: True),\n error_msg='Android-%s is not present in the NDK path.',\n )\n\n return android_ndk_api_level\n\n\ndef set_gcc_host_compiler_path(environ_cp):\n \"\"\"Set GCC_HOST_COMPILER_PATH.\"\"\"\n default_gcc_host_compiler_path = shutil.which('gcc') or ''\n\n gcc_host_compiler_path = prompt_loop_or_load_from_env(\n environ_cp,\n var_name='GCC_HOST_COMPILER_PATH',\n var_default=default_gcc_host_compiler_path,\n ask_for_var='Please specify which gcc should be used by nvcc as the host '\n 'compiler.',\n check_success=os.path.exists,\n resolve_symlinks=True,\n error_msg='Invalid gcc path. %s cannot be found.',\n )\n\n write_action_env_to_bazelrc('GCC_HOST_COMPILER_PATH', gcc_host_compiler_path)\n\n\ndef choose_compiler(environ_cp):\n question = 'Do you want to use Clang to build TensorFlow?'\n yes_reply = 'Clang will be used to compile TensorFlow.'\n no_reply = 'GCC will be used to compile TensorFlow.'\n var = int(\n get_var(\n environ_cp, 'TF_NEED_CLANG', None, True, question, yes_reply, no_reply\n )\n )\n return var\n\n\ndef choose_compiler_Win(environ_cp):\n question = 'Do you want to use Clang to build TensorFlow?'\n yes_reply = 'Add \"--config=win_clang\" to compile TensorFlow with CLANG.'\n no_reply = 'MSVC will be used to compile TensorFlow.'\n var = int(\n get_var(\n environ_cp, 'TF_NEED_CLANG', None, True, question, yes_reply, no_reply\n )\n )\n return var\n\n\ndef set_clang_compiler_path(environ_cp):\n \"\"\"Set CLANG_COMPILER_PATH and environment variables.\n\n Loop over user prompts for clang path until receiving a valid response.\n Default is used if no input is given. Set CLANG_COMPILER_PATH and write\n environment variables CC and BAZEL_COMPILER to .bazelrc.\n\n Args:\n environ_cp: (Dict) copy of the os.environ.\n\n Returns:\n string value for clang_compiler_path.\n \"\"\"\n # Default path if clang-18 is installed by using apt-get install\n # remove 16 logic upon release of 19\n default_clang_path = '/usr/lib/llvm-18/bin/clang'\n if not os.path.exists(default_clang_path):\n default_clang_path = '/usr/lib/llvm-17/bin/clang'\n if not os.path.exists(default_clang_path):\n default_clang_path = '/usr/lib/llvm-16/bin/clang'\n if not os.path.exists(default_clang_path):\n default_clang_path = shutil.which('clang') or ''\n\n clang_compiler_path = prompt_loop_or_load_from_env(\n environ_cp,\n var_name='CLANG_COMPILER_PATH',\n var_default=default_clang_path,\n ask_for_var='Please specify the path to clang executable.',\n check_success=os.path.exists,\n resolve_symlinks=True,\n error_msg=(\n 'Invalid clang path. %s cannot be found. Note that TensorFlow now'\n ' requires clang to compile. You may override this behavior by'\n ' setting TF_NEED_CLANG=0'\n ),\n )\n\n write_action_env_to_bazelrc('CLANG_COMPILER_PATH', clang_compiler_path)\n write_to_bazelrc('build --repo_env=CC=%s' % clang_compiler_path)\n write_to_bazelrc('build --repo_env=BAZEL_COMPILER=%s' % clang_compiler_path)\n\n return clang_compiler_path\n\n\ndef set_clang_compiler_path_win(environ_cp):\n \"\"\"Set CLANG_COMPILER_PATH and environment variables.\n\n Loop over user prompts for clang path until receiving a valid response.\n Default is used if no input is given. Set CLANG_COMPILER_PATH and write\n environment variables CC and BAZEL_COMPILER to .bazelrc.\n\n Args:\n environ_cp: (Dict) copy of the os.environ.\n\n Returns:\n string value for clang_compiler_path.\n \"\"\"\n # Default path if clang-16 is installed by using apt-get install\n default_clang_path = 'C:/Program Files/LLVM/bin/clang.exe'\n if not os.path.exists(default_clang_path):\n default_clang_path = shutil.which('clang') or ''\n\n clang_compiler_path = prompt_loop_or_load_from_env(\n environ_cp,\n var_name='CLANG_COMPILER_PATH',\n var_default=default_clang_path,\n ask_for_var='Please specify the path to clang executable.',\n check_success=os.path.exists,\n resolve_symlinks=True,\n error_msg=(\n 'Invalid clang path. %s cannot be found. Note that Clang is now'\n 'preferred compiler. You may use MSVC by removing --config=win_clang'\n ),\n )\n\n write_action_env_to_bazelrc('CLANG_COMPILER_PATH', clang_compiler_path)\n write_to_bazelrc(f'build --repo_env=CC=\"{clang_compiler_path}\"')\n write_to_bazelrc(f'build --repo_env=BAZEL_COMPILER=\"{clang_compiler_path}\"')\n\n return clang_compiler_path\n\n\ndef retrieve_clang_version(clang_executable):\n \"\"\"Retrieve installed clang version.\n\n Args:\n clang_executable: (String) path to clang executable\n\n Returns:\n The clang version detected.\n \"\"\"\n stderr = open(os.devnull, 'wb')\n curr_version = run_shell([clang_executable, '--version'],\n allow_non_zero=True,\n stderr=stderr)\n\n curr_version_split = curr_version.lower().split('clang version ')\n if len(curr_version_split) > 1:\n curr_version = curr_version_split[1].split()[0].split('git')\n\n if len(curr_version) > 1:\n print('WARNING: current clang installation is not a release version.\\n')\n\n curr_version = curr_version[0]\n curr_version_int = convert_version_to_int(curr_version)\n # Check if current clang version can be detected properly.\n if not curr_version_int:\n print('WARNING: current clang installation version unknown.\\n')\n return None\n\n print('You have Clang %s installed.\\n' % curr_version)\n return curr_version\n\n\n# Disable clang extension that rejects type definitions within offsetof.\n# This was added in clang-16 by https://reviews.llvm.org/D133574.\n# Still required for clang-17.\n# Can be removed once upb is updated, since a type definition is used within\n# offset of in the current version of ubp. See\n# https://github.com/protocolbuffers/upb/blob/9effcbcb27f0a665f9f345030188c0b291e32482/upb/upb.c#L183.\ndef disable_clang_offsetof_extension(clang_version):\n if int(clang_version.split('.')[0]) in (16, 17):\n write_to_bazelrc('build --copt=-Wno-gnu-offsetof-extensions')\n\n\ndef set_hermetic_cuda_version(environ_cp):\n \"\"\"Set HERMETIC_CUDA_VERSION.\"\"\"\n ask_cuda_version = (\n 'Please specify the hermetic CUDA version you want to use '\n 'or leave empty to use the default version. '\n )\n hermetic_cuda_version = get_from_env_or_user_or_default(\n environ_cp, 'HERMETIC_CUDA_VERSION', ask_cuda_version, None\n )\n if hermetic_cuda_version:\n environ_cp['HERMETIC_CUDA_VERSION'] = hermetic_cuda_version\n write_repo_env_to_bazelrc(\n 'cuda', 'HERMETIC_CUDA_VERSION', hermetic_cuda_version\n )\n\n\ndef set_hermetic_cudnn_version(environ_cp):\n \"\"\"Set HERMETIC_CUDNN_VERSION.\"\"\"\n ask_cudnn_version = (\n 'Please specify the hermetic cuDNN version you want to use '\n 'or leave empty to use the default version. '\n )\n hermetic_cudnn_version = get_from_env_or_user_or_default(\n environ_cp, 'HERMETIC_CUDNN_VERSION', ask_cudnn_version, None\n )\n if hermetic_cudnn_version:\n environ_cp['HERMETIC_CUDNN_VERSION'] = hermetic_cudnn_version\n write_repo_env_to_bazelrc(\n 'cuda', 'HERMETIC_CUDNN_VERSION', hermetic_cudnn_version\n )\n\n\ndef set_hermetic_cuda_compute_capabilities(environ_cp):\n \"\"\"Set HERMETIC_CUDA_COMPUTE_CAPABILITIES.\"\"\"\n while True:\n default_cuda_compute_capabilities = _DEFAULT_CUDA_COMPUTE_CAPABILITIES\n\n ask_cuda_compute_capabilities = (\n 'Please specify a list of comma-separated CUDA compute capabilities '\n 'you want to build with.\\nYou can find the compute capability of your '\n 'device at: https://developer.nvidia.com/cuda-gpus. Each capability '\n 'can be specified as \"x.y\" or \"compute_xy\" to include both virtual and'\n ' binary GPU code, or as \"sm_xy\" to only include the binary '\n 'code.\\nPlease note that each additional compute capability '\n 'significantly increases your build time and binary size, and that '\n 'TensorFlow only supports compute capabilities >= 3.5 [Default is: '\n '%s]: ' % default_cuda_compute_capabilities)\n hermetic_cuda_compute_capabilities = get_from_env_or_user_or_default(\n environ_cp,\n 'HERMETIC_CUDA_COMPUTE_CAPABILITIES',\n ask_cuda_compute_capabilities,\n default_cuda_compute_capabilities,\n )\n # Check whether all capabilities from the input is valid\n all_valid = True\n # Remove all whitespace characters before splitting the string\n # that users may insert by accident, as this will result in error\n hermetic_cuda_compute_capabilities = ''.join(\n hermetic_cuda_compute_capabilities.split()\n )\n for compute_capability in hermetic_cuda_compute_capabilities.split(','):\n m = re.match('[0-9]+.[0-9]+', compute_capability)\n if not m:\n # We now support sm_35,sm_50,sm_60,compute_70.\n sm_compute_match = re.match('(sm|compute)_?([0-9]+[0-9]+)',\n compute_capability)\n if not sm_compute_match:\n print('Invalid compute capability: %s' % compute_capability)\n all_valid = False\n else:\n ver = int(sm_compute_match.group(2))\n if ver < 30:\n print(\n 'ERROR: TensorFlow only supports small CUDA compute'\n ' capabilities of sm_30 and higher. Please re-specify the list'\n ' of compute capabilities excluding version %s.' % ver)\n all_valid = False\n if ver < 35:\n print('WARNING: XLA does not support CUDA compute capabilities '\n 'lower than sm_35. Disable XLA when running on older GPUs.')\n else:\n ver = float(m.group(0))\n if ver < 3.0:\n print('ERROR: TensorFlow only supports CUDA compute capabilities 3.0 '\n 'and higher. Please re-specify the list of compute '\n 'capabilities excluding version %s.' % ver)\n all_valid = False\n if ver < 3.5:\n print('WARNING: XLA does not support CUDA compute capabilities '\n 'lower than 3.5. Disable XLA when running on older GPUs.')\n\n if all_valid:\n break\n\n # Reset and Retry\n environ_cp['HERMETIC_CUDA_COMPUTE_CAPABILITIES'] = ''\n\n # Set HERMETIC_CUDA_COMPUTE_CAPABILITIES\n environ_cp['HERMETIC_CUDA_COMPUTE_CAPABILITIES'] = (\n hermetic_cuda_compute_capabilities\n )\n write_repo_env_to_bazelrc(\n 'cuda',\n 'HERMETIC_CUDA_COMPUTE_CAPABILITIES',\n hermetic_cuda_compute_capabilities,\n )\n\n\ndef set_cuda_local_path(environ_cp, dist_name, env_var):\n ask_path = (\n 'Please specify the local {} path you want to use '\n 'or leave empty to use the default version. '\n ).format(dist_name)\n local_path = get_from_env_or_user_or_default(\n environ_cp, env_var, ask_path, None\n )\n if local_path:\n environ_cp[env_var] = local_path\n write_repo_env_to_bazelrc('cuda', env_var, local_path)\n\n\ndef set_other_cuda_vars(environ_cp):\n \"\"\"Set other CUDA related variables.\"\"\"\n # If CUDA is enabled, always use GPU during build and test.\n if environ_cp.get('TF_CUDA_CLANG') == '1':\n write_to_bazelrc('build --config=cuda_clang')\n else:\n write_to_bazelrc('build --config=cuda')\n\n\ndef system_specific_test_config(environ_cp):\n \"\"\"Add default build and test flags required for TF tests to bazelrc.\"\"\"\n write_to_bazelrc('test --test_size_filters=small,medium')\n\n # Each instance of --test_tag_filters or --build_tag_filters overrides all\n # previous instances, so we need to build up a complete list and write a\n # single list of filters for the .bazelrc file.\n\n # Filters to use with both --test_tag_filters and --build_tag_filters\n test_and_build_filters = ['-benchmark-test', '-no_oss', '-oss_excluded']\n # Additional filters for --test_tag_filters beyond those in\n # test_and_build_filters\n test_only_filters = ['-oss_serial']\n if is_windows():\n test_and_build_filters += ['-no_windows', '-windows_excluded']\n if ((environ_cp.get('TF_NEED_CUDA', None) == '1') or\n (environ_cp.get('TF_NEED_ROCM', None) == '1')):\n test_and_build_filters += ['-no_windows_gpu', '-no_gpu']\n else:\n test_and_build_filters.append('-gpu')\n elif is_macos():\n test_and_build_filters += ['-gpu', '-nomac', '-no_mac', '-mac_excluded']\n elif is_linux():\n if ((environ_cp.get('TF_NEED_CUDA', None) == '1') or\n (environ_cp.get('TF_NEED_ROCM', None) == '1')):\n test_and_build_filters.append('-no_gpu')\n write_to_bazelrc('test --test_env=LD_LIBRARY_PATH')\n else:\n test_and_build_filters.append('-gpu')\n\n # Disable tests with \"v1only\" tag in \"v2\" Bazel config, but not in \"v1\" config\n write_to_bazelrc('test:v1 --test_tag_filters=%s' %\n ','.join(test_and_build_filters + test_only_filters))\n write_to_bazelrc('test:v1 --build_tag_filters=%s' %\n ','.join(test_and_build_filters))\n write_to_bazelrc(\n 'test:v2 --test_tag_filters=%s' %\n ','.join(test_and_build_filters + test_only_filters + ['-v1only']))\n write_to_bazelrc('test:v2 --build_tag_filters=%s' %\n ','.join(test_and_build_filters + ['-v1only']))\n\n\ndef set_system_libs_flag(environ_cp):\n \"\"\"Set system libs flags.\"\"\"\n syslibs = environ_cp.get('TF_SYSTEM_LIBS', '')\n\n if is_s390x() and 'boringssl' not in syslibs:\n syslibs = 'boringssl' + (', ' + syslibs if syslibs else '')\n\n if syslibs:\n if ',' in syslibs:\n syslibs = ','.join(sorted(syslibs.split(',')))\n else:\n syslibs = ','.join(sorted(syslibs.split()))\n write_action_env_to_bazelrc('TF_SYSTEM_LIBS', syslibs)\n\n for varname in ('PREFIX', 'LIBDIR', 'INCLUDEDIR', 'PROTOBUF_INCLUDE_PATH'):\n if varname in environ_cp:\n write_to_bazelrc('build --define=%s=%s' % (varname, environ_cp[varname]))\n\n\ndef set_windows_build_flags(environ_cp):\n \"\"\"Set Windows specific build options.\"\"\"\n\n # First available in VS 16.4. Speeds up Windows compile times by a lot. See\n # https://groups.google.com/a/tensorflow.org/d/topic/build/SsW98Eo7l3o/discussion\n # pylint: disable=line-too-long\n write_to_bazelrc(\n 'build --copt=/d2ReducedOptimizeHugeFunctions --host_copt=/d2ReducedOptimizeHugeFunctions'\n )\n\n if get_var(\n environ_cp, 'TF_OVERRIDE_EIGEN_STRONG_INLINE', 'Eigen strong inline',\n True, ('Would you like to override eigen strong inline for some C++ '\n 'compilation to reduce the compilation time?'),\n 'Eigen strong inline overridden.', 'Not overriding eigen strong inline, '\n 'some compilations could take more than 20 mins.'):\n # Due to a known MSVC compiler issue\n # https://github.com/tensorflow/tensorflow/issues/10521\n # Overriding eigen strong inline speeds up the compiling of\n # conv_grad_ops_3d.cc and conv_ops_3d.cc by 20 minutes,\n # but this also hurts the performance. Let users decide what they want.\n write_to_bazelrc('build --define=override_eigen_strong_inline=true')\n\n\ndef config_info_line(name, help_text):\n \"\"\"Helper function to print formatted help text for Bazel config options.\"\"\"\n print('\\t--config=%-12s\\t# %s' % (name, help_text))\n\n\ndef configure_ios(environ_cp):\n \"\"\"Configures TensorFlow for iOS builds.\"\"\"\n if not is_macos():\n return\n if not get_var(environ_cp, 'TF_CONFIGURE_IOS', 'iOS', False):\n return\n for filepath in APPLE_BAZEL_FILES:\n existing_filepath = os.path.join(_TF_WORKSPACE_ROOT, filepath + '.apple')\n renamed_filepath = os.path.join(_TF_WORKSPACE_ROOT, filepath)\n symlink_force(existing_filepath, renamed_filepath)\n for filepath in IOS_FILES:\n filename = os.path.basename(filepath)\n new_filepath = os.path.join(_TF_WORKSPACE_ROOT, filename)\n symlink_force(filepath, new_filepath)\n\n\ndef get_gcc_compiler(environ_cp):\n gcc_env = environ_cp.get('CXX') or environ_cp.get('CC') or shutil.which('gcc')\n if gcc_env is not None:\n gcc_version = run_shell([gcc_env, '--version']).split()\n if gcc_version[0] in ('gcc', 'g++'):\n return gcc_env\n return None\n\n\ndef main():\n global _TF_WORKSPACE_ROOT\n global _TF_BAZELRC\n global _TF_CURRENT_BAZEL_VERSION\n\n parser = argparse.ArgumentParser()\n parser.add_argument(\n '--workspace',\n type=str,\n default=os.path.abspath(os.path.dirname(__file__)),\n help='The absolute path to your active Bazel workspace.')\n args = parser.parse_args()\n\n _TF_WORKSPACE_ROOT = args.workspace\n _TF_BAZELRC = os.path.join(_TF_WORKSPACE_ROOT, _TF_BAZELRC_FILENAME)\n\n # Make a copy of os.environ to be clear when functions and getting and setting\n # environment variables.\n environ_cp = dict(os.environ)\n\n try:\n current_bazel_version = retrieve_bazel_version()\n except subprocess.CalledProcessError as e:\n print('Error retrieving bazel version: ', e.output.decode('UTF-8').strip())\n raise e\n\n _TF_CURRENT_BAZEL_VERSION = convert_version_to_int(current_bazel_version)\n\n reset_tf_configure_bazelrc()\n\n cleanup_makefile()\n setup_python(environ_cp)\n\n if is_windows():\n environ_cp['TF_NEED_OPENCL'] = '0'\n environ_cp['TF_CUDA_CLANG'] = '0'\n # TODO(ibiryukov): Investigate using clang as a cpu or cuda compiler on\n # Windows.\n environ_cp['TF_DOWNLOAD_CLANG'] = '0'\n environ_cp['TF_NEED_MPI'] = '0'\n\n if is_ppc64le():\n # Enable MMA Dynamic Dispatch support if 'gcc' and if linker >= 2.35\n gcc_env = get_gcc_compiler(environ_cp)\n if gcc_env is not None:\n\n # Use gold linker if 'gcc' and if 'ppc64le'\n write_to_bazelrc('build --linkopt=\"-fuse-ld=gold\"')\n\n # Get the linker version\n ld_version = run_shell([gcc_env, '-Wl,-version']).split()\n\n ld_version_int = convert_version_to_int(ld_version[3])\n if ld_version_int is None:\n ld_version_int = convert_version_to_int(ld_version[4])\n\n # Enable if 'ld' version >= 2.35\n if ld_version_int >= 2035000:\n write_to_bazelrc(\n 'build --copt=\"-DEIGEN_ALTIVEC_ENABLE_MMA_DYNAMIC_DISPATCH=1\"')\n\n with_xla_support = environ_cp.get('TF_ENABLE_XLA', None)\n if with_xla_support is not None:\n write_to_bazelrc('build --define=with_xla_support=%s' %\n ('true' if int(with_xla_support) else 'false'))\n\n set_action_env_var(\n environ_cp, 'TF_NEED_ROCM', 'ROCm', False, bazel_config_name='rocm')\n if (environ_cp.get('TF_NEED_ROCM') == '1' and\n 'LD_LIBRARY_PATH' in environ_cp and\n environ_cp.get('LD_LIBRARY_PATH') != '1'):\n write_action_env_to_bazelrc('LD_LIBRARY_PATH',\n environ_cp.get('LD_LIBRARY_PATH'))\n\n if (environ_cp.get('TF_NEED_ROCM') == '1' and environ_cp.get('ROCM_PATH')):\n write_action_env_to_bazelrc('ROCM_PATH', environ_cp.get('ROCM_PATH'))\n\n if (environ_cp.get('TF_NEED_ROCM') == '1' and environ_cp.get('HIP_PLATFORM')):\n write_action_env_to_bazelrc('HIP_PLATFORM', environ_cp.get('HIP_PLATFORM'))\n\n if is_windows():\n print('\\nWARNING: Cannot build with CUDA support on Windows.\\n'\n 'Starting in TF 2.11, CUDA build is not supported for Windows. '\n 'For using TensorFlow GPU on Windows, you will need to build/install '\n 'TensorFlow in WSL2.\\n')\n environ_cp['TF_NEED_CUDA'] = '0'\n else:\n environ_cp['TF_NEED_CUDA'] = str(\n int(get_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)))\n if environ_cp.get('TF_NEED_CUDA') == '1':\n set_hermetic_cuda_version(environ_cp)\n set_hermetic_cudnn_version(environ_cp)\n set_hermetic_cuda_compute_capabilities(environ_cp)\n set_cuda_local_path(environ_cp, 'CUDA', 'LOCAL_CUDA_PATH')\n set_cuda_local_path(environ_cp, 'CUDNN', 'LOCAL_CUDNN_PATH')\n set_cuda_local_path(environ_cp, 'NCCL', 'LOCAL_NCCL_PATH')\n\n if 'LD_LIBRARY_PATH' in environ_cp and environ_cp.get(\n 'LD_LIBRARY_PATH') != '1':\n write_action_env_to_bazelrc('LD_LIBRARY_PATH',\n environ_cp.get('LD_LIBRARY_PATH'))\n\n set_tf_cuda_clang(environ_cp)\n if environ_cp.get('TF_CUDA_CLANG') == '1':\n # Set up which clang we should use as the cuda / host compiler.\n clang_cuda_compiler_path = set_clang_cuda_compiler_path(environ_cp)\n clang_version = retrieve_clang_version(clang_cuda_compiler_path)\n disable_clang_offsetof_extension(clang_version)\n else:\n # Set up which gcc nvcc should use as the host compiler\n # No need to set this on Windows\n if not is_windows():\n set_gcc_host_compiler_path(environ_cp)\n set_other_cuda_vars(environ_cp)\n else:\n # CUDA not required. Ask whether we should use clang for the CPU build.\n if is_linux():\n environ_cp['TF_NEED_CLANG'] = str(choose_compiler(environ_cp))\n if environ_cp.get('TF_NEED_CLANG') == '1':\n clang_compiler_path = set_clang_compiler_path(environ_cp)\n clang_version = retrieve_clang_version(clang_compiler_path)\n disable_clang_offsetof_extension(clang_version)\n if is_windows():\n environ_cp['TF_NEED_CLANG'] = str(choose_compiler_Win(environ_cp))\n if environ_cp.get('TF_NEED_CLANG') == '1':\n clang_compiler_path = set_clang_compiler_path_win(environ_cp)\n clang_version = retrieve_clang_version(clang_compiler_path)\n disable_clang_offsetof_extension(clang_version)\n\n # ROCm / CUDA are mutually exclusive.\n # At most 1 GPU platform can be configured.\n gpu_platform_count = 0\n if environ_cp.get('TF_NEED_ROCM') == '1':\n gpu_platform_count += 1\n if environ_cp.get('TF_NEED_CUDA') == '1':\n gpu_platform_count += 1\n if gpu_platform_count >= 2:\n raise UserInputError('CUDA / ROCm are mututally exclusive. '\n 'At most 1 GPU platform can be configured.')\n\n set_cc_opt_flags(environ_cp)\n set_system_libs_flag(environ_cp)\n if is_windows():\n set_windows_build_flags(environ_cp)\n\n if get_var(environ_cp, 'TF_SET_ANDROID_WORKSPACE', 'android workspace', False,\n ('Would you like to interactively configure ./WORKSPACE for '\n 'Android builds?'), 'Searching for NDK and SDK installations.',\n 'Not configuring the WORKSPACE for Android builds.'):\n create_android_ndk_rule(environ_cp)\n create_android_sdk_rule(environ_cp)\n\n system_specific_test_config(environ_cp)\n\n configure_ios(environ_cp)\n\n print('Preconfigured Bazel build configs. You can use any of the below by '\n 'adding \"--config=<>\" to your build command. See .bazelrc for more '\n 'details.')\n config_info_line('mkl', 'Build with MKL support.')\n config_info_line(\n 'mkl_aarch64',\n 'Build with oneDNN and Compute Library for the Arm Architecture (ACL).')\n config_info_line('monolithic', 'Config for mostly static monolithic build.')\n config_info_line('numa', 'Build with NUMA support.')\n config_info_line(\n 'dynamic_kernels',\n '(Experimental) Build kernels into separate shared objects.')\n config_info_line('v1', 'Build with TensorFlow 1 API instead of TF 2 API.')\n\n print('Preconfigured Bazel build configs to DISABLE default on features:')\n config_info_line('nogcp', 'Disable GCP support.')\n config_info_line('nonccl', 'Disable NVIDIA NCCL support.')\n\n\nif __name__ == '__main__':\n main()\n" | |
| } | |
| ] | |
| }, | |
| { | |
| "url": "https://github.com/huggingface/transformers", | |
| "files": [ | |
| { | |
| "name": "conftest.py", | |
| "content": "# Copyright 2020 The HuggingFace Team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# tests directory-specific settings - this file is run automatically\n# by pytest before any tests are run\n\nimport doctest\nimport sys\nimport warnings\nfrom os.path import abspath, dirname, join\n\nimport _pytest\nimport pytest\n\nfrom transformers.testing_utils import HfDoctestModule, HfDocTestParser\n\n\nNOT_DEVICE_TESTS = {\n \"test_tokenization\",\n \"test_processor\",\n \"test_processing\",\n \"test_beam_constraints\",\n \"test_configuration_utils\",\n \"test_data_collator\",\n \"test_trainer_callback\",\n \"test_trainer_utils\",\n \"test_feature_extraction\",\n \"test_image_processing\",\n \"test_image_processor\",\n \"test_image_transforms\",\n \"test_optimization\",\n \"test_retrieval\",\n \"test_config\",\n \"test_from_pretrained_no_checkpoint\",\n \"test_keep_in_fp32_modules\",\n \"test_gradient_checkpointing_backward_compatibility\",\n \"test_gradient_checkpointing_enable_disable\",\n \"test_save_load_fast_init_from_base\",\n \"test_fast_init_context_manager\",\n \"test_fast_init_tied_embeddings\",\n \"test_save_load_fast_init_to_base\",\n \"test_torch_save_load\",\n \"test_initialization\",\n \"test_forward_signature\",\n \"test_model_get_set_embeddings\",\n \"test_model_main_input_name\",\n \"test_correct_missing_keys\",\n \"test_tie_model_weights\",\n \"test_can_use_safetensors\",\n \"test_load_save_without_tied_weights\",\n \"test_tied_weights_keys\",\n \"test_model_weights_reload_no_missing_tied_weights\",\n \"test_pt_tf_model_equivalence\",\n \"test_mismatched_shapes_have_properly_initialized_weights\",\n \"test_matched_shapes_have_loaded_weights_when_some_mismatched_shapes_exist\",\n \"test_model_is_small\",\n \"test_tf_from_pt_safetensors\",\n \"test_flax_from_pt_safetensors\",\n \"ModelTest::test_pipeline_\", # None of the pipeline tests from PipelineTesterMixin (of which XxxModelTest inherits from) are running on device\n \"ModelTester::test_pipeline_\",\n \"/repo_utils/\",\n \"/utils/\",\n \"/agents/\",\n}\n\n# allow having multiple repository checkouts and not needing to remember to rerun\n# `pip install -e '.[dev]'` when switching between checkouts and running tests.\ngit_repo_path = abspath(join(dirname(__file__), \"src\"))\nsys.path.insert(1, git_repo_path)\n\n# silence FutureWarning warnings in tests since often we can't act on them until\n# they become normal warnings - i.e. the tests still need to test the current functionality\nwarnings.simplefilter(action=\"ignore\", category=FutureWarning)\n\n\ndef pytest_configure(config):\n config.addinivalue_line(\n \"markers\", \"is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested\"\n )\n config.addinivalue_line(\n \"markers\", \"is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested\"\n )\n config.addinivalue_line(\"markers\", \"is_pipeline_test: mark test to run only when pipelines are tested\")\n config.addinivalue_line(\"markers\", \"is_staging_test: mark test to run only in the staging environment\")\n config.addinivalue_line(\"markers\", \"accelerate_tests: mark test that require accelerate\")\n config.addinivalue_line(\"markers\", \"agent_tests: mark the agent tests that are run on their specific schedule\")\n config.addinivalue_line(\"markers\", \"not_device_test: mark the tests always running on cpu\")\n\n\ndef pytest_collection_modifyitems(items):\n for item in items:\n if any(test_name in item.nodeid for test_name in NOT_DEVICE_TESTS):\n item.add_marker(pytest.mark.not_device_test)\n\n\ndef pytest_addoption(parser):\n from transformers.testing_utils import pytest_addoption_shared\n\n pytest_addoption_shared(parser)\n\n\ndef pytest_terminal_summary(terminalreporter):\n from transformers.testing_utils import pytest_terminal_summary_main\n\n make_reports = terminalreporter.config.getoption(\"--make-reports\")\n if make_reports:\n pytest_terminal_summary_main(terminalreporter, id=make_reports)\n\n\ndef pytest_sessionfinish(session, exitstatus):\n # If no tests are collected, pytest exists with code 5, which makes the CI fail.\n if exitstatus == 5:\n session.exitstatus = 0\n\n\n# Doctest custom flag to ignore output.\nIGNORE_RESULT = doctest.register_optionflag(\"IGNORE_RESULT\")\n\nOutputChecker = doctest.OutputChecker\n\n\nclass CustomOutputChecker(OutputChecker):\n def check_output(self, want, got, optionflags):\n if IGNORE_RESULT & optionflags:\n return True\n return OutputChecker.check_output(self, want, got, optionflags)\n\n\ndoctest.OutputChecker = CustomOutputChecker\n_pytest.doctest.DoctestModule = HfDoctestModule\ndoctest.DocTestParser = HfDocTestParser\n" | |
| }, | |
| { | |
| "name": "hubconf.py", | |
| "content": "# Copyright 2020 The HuggingFace Team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport os\nimport sys\n\n\nSRC_DIR = os.path.join(os.path.dirname(__file__), \"src\")\nsys.path.append(SRC_DIR)\n\n\nfrom transformers import (\n AutoConfig,\n AutoModel,\n AutoModelForCausalLM,\n AutoModelForMaskedLM,\n AutoModelForQuestionAnswering,\n AutoModelForSequenceClassification,\n AutoTokenizer,\n add_start_docstrings,\n)\n\n\ndependencies = [\"torch\", \"numpy\", \"tokenizers\", \"filelock\", \"requests\", \"tqdm\", \"regex\", \"sentencepiece\", \"sacremoses\", \"importlib_metadata\", \"huggingface_hub\"]\n\n\n@add_start_docstrings(AutoConfig.__doc__)\ndef config(*args, **kwargs):\n r\"\"\"\n # Using torch.hub !\n import torch\n\n config = torch.hub.load('huggingface/transformers', 'config', 'google-bert/bert-base-uncased') # Download configuration from huggingface.co and cache.\n config = torch.hub.load('huggingface/transformers', 'config', './test/bert_saved_model/') # E.g. config (or model) was saved using `save_pretrained('./test/saved_model/')`\n config = torch.hub.load('huggingface/transformers', 'config', './test/bert_saved_model/my_configuration.json')\n config = torch.hub.load('huggingface/transformers', 'config', 'google-bert/bert-base-uncased', output_attentions=True, foo=False)\n assert config.output_attentions == True\n config, unused_kwargs = torch.hub.load('huggingface/transformers', 'config', 'google-bert/bert-base-uncased', output_attentions=True, foo=False, return_unused_kwargs=True)\n assert config.output_attentions == True\n assert unused_kwargs == {'foo': False}\n\n \"\"\"\n\n return AutoConfig.from_pretrained(*args, **kwargs)\n\n\n@add_start_docstrings(AutoTokenizer.__doc__)\ndef tokenizer(*args, **kwargs):\n r\"\"\"\n # Using torch.hub !\n import torch\n\n tokenizer = torch.hub.load('huggingface/transformers', 'tokenizer', 'google-bert/bert-base-uncased') # Download vocabulary from huggingface.co and cache.\n tokenizer = torch.hub.load('huggingface/transformers', 'tokenizer', './test/bert_saved_model/') # E.g. tokenizer was saved using `save_pretrained('./test/saved_model/')`\n\n \"\"\"\n\n return AutoTokenizer.from_pretrained(*args, **kwargs)\n\n\n@add_start_docstrings(AutoModel.__doc__)\ndef model(*args, **kwargs):\n r\"\"\"\n # Using torch.hub !\n import torch\n\n model = torch.hub.load('huggingface/transformers', 'model', 'google-bert/bert-base-uncased') # Download model and configuration from huggingface.co and cache.\n model = torch.hub.load('huggingface/transformers', 'model', './test/bert_model/') # E.g. model was saved using `save_pretrained('./test/saved_model/')`\n model = torch.hub.load('huggingface/transformers', 'model', 'google-bert/bert-base-uncased', output_attentions=True) # Update configuration during loading\n assert model.config.output_attentions == True\n # Loading from a TF checkpoint file instead of a PyTorch model (slower)\n config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json')\n model = torch.hub.load('huggingface/transformers', 'model', './tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)\n\n \"\"\"\n\n return AutoModel.from_pretrained(*args, **kwargs)\n\n\n@add_start_docstrings(AutoModelForCausalLM.__doc__)\ndef modelForCausalLM(*args, **kwargs):\n r\"\"\"\n # Using torch.hub !\n import torch\n\n model = torch.hub.load('huggingface/transformers', 'modelForCausalLM', 'openai-community/gpt2') # Download model and configuration from huggingface.co and cache.\n model = torch.hub.load('huggingface/transformers', 'modelForCausalLM', './test/saved_model/') # E.g. model was saved using `save_pretrained('./test/saved_model/')`\n model = torch.hub.load('huggingface/transformers', 'modelForCausalLM', 'openai-community/gpt2', output_attentions=True) # Update configuration during loading\n assert model.config.output_attentions == True\n # Loading from a TF checkpoint file instead of a PyTorch model (slower)\n config = AutoConfig.from_pretrained('./tf_model/gpt_tf_model_config.json')\n model = torch.hub.load('huggingface/transformers', 'modelForCausalLM', './tf_model/gpt_tf_checkpoint.ckpt.index', from_tf=True, config=config)\n\n \"\"\"\n return AutoModelForCausalLM.from_pretrained(*args, **kwargs)\n\n\n@add_start_docstrings(AutoModelForMaskedLM.__doc__)\ndef modelForMaskedLM(*args, **kwargs):\n r\"\"\"\n # Using torch.hub !\n import torch\n\n model = torch.hub.load('huggingface/transformers', 'modelForMaskedLM', 'google-bert/bert-base-uncased') # Download model and configuration from huggingface.co and cache.\n model = torch.hub.load('huggingface/transformers', 'modelForMaskedLM', './test/bert_model/') # E.g. model was saved using `save_pretrained('./test/saved_model/')`\n model = torch.hub.load('huggingface/transformers', 'modelForMaskedLM', 'google-bert/bert-base-uncased', output_attentions=True) # Update configuration during loading\n assert model.config.output_attentions == True\n # Loading from a TF checkpoint file instead of a PyTorch model (slower)\n config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json')\n model = torch.hub.load('huggingface/transformers', 'modelForMaskedLM', './tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)\n\n \"\"\"\n\n return AutoModelForMaskedLM.from_pretrained(*args, **kwargs)\n\n\n@add_start_docstrings(AutoModelForSequenceClassification.__doc__)\ndef modelForSequenceClassification(*args, **kwargs):\n r\"\"\"\n # Using torch.hub !\n import torch\n\n model = torch.hub.load('huggingface/transformers', 'modelForSequenceClassification', 'google-bert/bert-base-uncased') # Download model and configuration from huggingface.co and cache.\n model = torch.hub.load('huggingface/transformers', 'modelForSequenceClassification', './test/bert_model/') # E.g. model was saved using `save_pretrained('./test/saved_model/')`\n model = torch.hub.load('huggingface/transformers', 'modelForSequenceClassification', 'google-bert/bert-base-uncased', output_attentions=True) # Update configuration during loading\n assert model.config.output_attentions == True\n # Loading from a TF checkpoint file instead of a PyTorch model (slower)\n config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json')\n model = torch.hub.load('huggingface/transformers', 'modelForSequenceClassification', './tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)\n\n \"\"\"\n\n return AutoModelForSequenceClassification.from_pretrained(*args, **kwargs)\n\n\n@add_start_docstrings(AutoModelForQuestionAnswering.__doc__)\ndef modelForQuestionAnswering(*args, **kwargs):\n r\"\"\"\n # Using torch.hub !\n import torch\n\n model = torch.hub.load('huggingface/transformers', 'modelForQuestionAnswering', 'google-bert/bert-base-uncased') # Download model and configuration from huggingface.co and cache.\n model = torch.hub.load('huggingface/transformers', 'modelForQuestionAnswering', './test/bert_model/') # E.g. model was saved using `save_pretrained('./test/saved_model/')`\n model = torch.hub.load('huggingface/transformers', 'modelForQuestionAnswering', 'google-bert/bert-base-uncased', output_attentions=True) # Update configuration during loading\n assert model.config.output_attentions == True\n # Loading from a TF checkpoint file instead of a PyTorch model (slower)\n config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json')\n model = torch.hub.load('huggingface/transformers', 'modelForQuestionAnswering', './tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)\n\n \"\"\"\n return AutoModelForQuestionAnswering.from_pretrained(*args, **kwargs)\n" | |
| }, | |
| { | |
| "name": "setup.py", | |
| "content": "# Copyright 2021 The HuggingFace Team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nSimple check list from AllenNLP repo: https://github.com/allenai/allennlp/blob/main/setup.py\n\nTo create the package for pypi.\n\n1. Create the release branch named: v<RELEASE>-release, for example v4.19-release. For a patch release checkout the\n current release branch.\n\n If releasing on a special branch, copy the updated README.md on the main branch for your the commit you will make\n for the post-release and run `make fix-copies` on the main branch as well.\n\n2. Run `make pre-release` (or `make pre-patch` for a patch release) and commit these changes with the message:\n \"Release: <VERSION>\" and push.\n\n3. Go back to the main branch and run `make post-release` then `make fix-copies`. Commit these changes with the\n message \"v<NEXT_VERSION>.dev.0\" and push to main.\n\n# If you were just cutting the branch in preparation for a release, you can stop here for now.\n\n4. Wait for the tests on the release branch to be completed and be green (otherwise revert and fix bugs)\n\n5. On the release branch, add a tag in git to mark the release: \"git tag v<VERSION> -m 'Adds tag v<VERSION> for pypi' \"\n Push the tag to git: git push --tags origin v<RELEASE>-release\n\n6. Build both the sources and the wheel. Do not change anything in setup.py between\n creating the wheel and the source distribution (obviously).\n\n Run `make build-release`. This will build the release and do some sanity checks for you. If this ends with an error\n message, you need to fix things before going further.\n\n You should now have a /dist directory with both .whl and .tar.gz source versions.\n\n7. Check that everything looks correct by uploading the package to the pypi test server:\n\n twine upload dist/* -r testpypi\n (pypi suggest using twine as other methods upload files via plaintext.)\n You may have to specify the repository url, use the following command then:\n twine upload dist/* -r testpypi --repository-url=https://test.pypi.org/legacy/\n\n Check that you can install it in a virtualenv by running:\n pip install -i https://testpypi.python.org/pypi transformers\n\n Check you can run the following commands:\n python -c \"from transformers import pipeline; classifier = pipeline('text-classification'); print(classifier('What a nice release'))\"\n python -c \"from transformers import *\"\n python utils/check_build.py --check_lib\n\n If making a patch release, double check the bug you are patching is indeed resolved.\n\n8. Upload the final version to actual pypi:\n twine upload dist/* -r pypi\n\n9. Copy the release notes from RELEASE.md to the tag in github once everything is looking hunky-dory.\n\"\"\"\n\nimport os\nimport re\nimport shutil\nfrom pathlib import Path\n\nfrom setuptools import Command, find_packages, setup\n\n\n# Remove stale transformers.egg-info directory to avoid https://github.com/pypa/pip/issues/5466\nstale_egg_info = Path(__file__).parent / \"transformers.egg-info\"\nif stale_egg_info.exists():\n print(\n (\n \"Warning: {} exists.\\n\\n\"\n \"If you recently updated transformers to 3.0 or later, this is expected,\\n\"\n \"but it may prevent transformers from installing in editable mode.\\n\\n\"\n \"This directory is automatically generated by Python's packaging tools.\\n\"\n \"I will remove it now.\\n\\n\"\n \"See https://github.com/pypa/pip/issues/5466 for details.\\n\"\n ).format(stale_egg_info)\n )\n shutil.rmtree(stale_egg_info)\n\n\n# IMPORTANT:\n# 1. all dependencies should be listed here with their version requirements if any\n# 2. once modified, run: `make deps_table_update` to update src/transformers/dependency_versions_table.py\n_deps = [\n \"Pillow>=10.0.1,<=15.0\",\n \"accelerate>=0.26.0\",\n \"av==9.2.0\", # Latest version of PyAV (10.0.0) has issues with audio stream.\n \"beautifulsoup4\",\n \"blobfile\",\n \"codecarbon==1.2.0\",\n \"cookiecutter==1.7.3\",\n \"dataclasses\",\n \"datasets!=2.5.0\",\n \"deepspeed>=0.9.3\",\n \"diffusers\",\n \"dill<0.3.5\",\n \"evaluate>=0.2.0\",\n \"faiss-cpu\",\n \"fastapi\",\n \"filelock\",\n \"flax>=0.4.1,<=0.7.0\",\n \"fsspec<2023.10.0\",\n \"ftfy\",\n \"fugashi>=1.0\",\n \"GitPython<3.1.19\",\n \"hf-doc-builder>=0.3.0\",\n \"huggingface-hub>=0.23.2,<1.0\",\n \"importlib_metadata\",\n \"ipadic>=1.0.0,<2.0\",\n \"isort>=5.5.4\",\n \"jax>=0.4.1,<=0.4.13\",\n \"jaxlib>=0.4.1,<=0.4.13\",\n \"jieba\",\n \"jinja2>=3.1.0\",\n \"kenlm\",\n # Keras pin - this is to make sure Keras 3 doesn't destroy us. Remove or change when we have proper support.\n \"keras>2.9,<2.16\",\n \"keras-nlp>=0.3.1,<0.14.0\", # keras-nlp 0.14 doesn't support keras 2, see pin on keras.\n \"librosa\",\n \"nltk<=3.8.1\",\n \"natten>=0.14.6,<0.15.0\",\n \"numpy>=1.17\",\n \"onnxconverter-common\",\n \"onnxruntime-tools>=1.4.2\",\n \"onnxruntime>=1.4.0\",\n \"opencv-python\",\n \"optimum-benchmark>=0.3.0\",\n \"optuna\",\n \"optax>=0.0.8,<=0.1.4\",\n \"packaging>=20.0\",\n \"parameterized\",\n \"phonemizer\",\n \"protobuf\",\n \"psutil\",\n \"pyyaml>=5.1\",\n \"pydantic\",\n \"pytest>=7.2.0,<8.0.0\",\n \"pytest-timeout\",\n \"pytest-xdist\",\n \"python>=3.9.0\",\n \"ray[tune]>=2.7.0\",\n \"regex!=2019.12.17\",\n \"requests\",\n \"rhoknp>=1.1.0,<1.3.1\",\n \"rjieba\",\n \"rouge-score!=0.0.7,!=0.0.8,!=0.1,!=0.1.1\",\n \"ruff==0.5.1\",\n \"sacrebleu>=1.4.12,<2.0.0\",\n \"sacremoses\",\n \"safetensors>=0.4.1\",\n \"sagemaker>=2.31.0\",\n \"schedulefree>=1.2.6\",\n \"scikit-learn\",\n \"scipy<1.13.0\", # SciPy >= 1.13.0 is not supported with the current jax pin (`jax>=0.4.1,<=0.4.13`)\n \"sentencepiece>=0.1.91,!=0.1.92\",\n \"sigopt\",\n \"starlette\",\n \"sudachipy>=0.6.6\",\n \"sudachidict_core>=20220729\",\n \"tensorboard\",\n # TensorFlow pin. When changing this value, update examples/tensorflow/_tests_requirements.txt accordingly\n \"tensorflow-cpu>2.9,<2.16\",\n \"tensorflow>2.9,<2.16\",\n \"tensorflow-text<2.16\",\n \"tensorflow-probability<0.24\",\n \"tf2onnx\",\n \"timeout-decorator\",\n \"tiktoken\",\n \"timm<=0.9.16\",\n \"tokenizers>=0.20,<0.21\",\n \"torch\",\n \"torchaudio\",\n \"torchvision\",\n \"pyctcdecode>=0.4.0\",\n \"tqdm>=4.27\",\n \"unidic>=1.0.2\",\n \"unidic_lite>=1.0.7\",\n \"urllib3<2.0.0\",\n \"uvicorn\",\n \"pytest-rich\",\n \"libcst\",\n \"rich\",\n]\n\n\n# this is a lookup table with items like:\n#\n# tokenizers: \"tokenizers==0.9.4\"\n# packaging: \"packaging\"\n#\n# some of the values are versioned whereas others aren't.\ndeps = {b: a for a, b in (re.findall(r\"^(([^!=<>~ ]+)(?:[!=<>~ ].*)?$)\", x)[0] for x in _deps)}\n\n# since we save this data in src/transformers/dependency_versions_table.py it can be easily accessed from\n# anywhere. If you need to quickly access the data from this table in a shell, you can do so easily with:\n#\n# python -c 'import sys; from transformers.dependency_versions_table import deps; \\\n# print(\" \".join([ deps[x] for x in sys.argv[1:]]))' tokenizers datasets\n#\n# Just pass the desired package names to that script as it's shown with 2 packages above.\n#\n# If transformers is not yet installed and the work is done from the cloned repo remember to add `PYTHONPATH=src` to the script above\n#\n# You can then feed this for example to `pip`:\n#\n# pip install -U $(python -c 'import sys; from transformers.dependency_versions_table import deps; \\\n# print(\" \".join([deps[x] for x in sys.argv[1:]]))' tokenizers datasets)\n#\n\n\ndef deps_list(*pkgs):\n return [deps[pkg] for pkg in pkgs]\n\n\nclass DepsTableUpdateCommand(Command):\n \"\"\"\n A custom distutils command that updates the dependency table.\n usage: python setup.py deps_table_update\n \"\"\"\n\n description = \"build runtime dependency table\"\n user_options = [\n # format: (long option, short option, description).\n (\"dep-table-update\", None, \"updates src/transformers/dependency_versions_table.py\"),\n ]\n\n def initialize_options(self):\n pass\n\n def finalize_options(self):\n pass\n\n def run(self):\n entries = \"\\n\".join([f' \"{k}\": \"{v}\",' for k, v in deps.items()])\n content = [\n \"# THIS FILE HAS BEEN AUTOGENERATED. To update:\",\n \"# 1. modify the `_deps` dict in setup.py\",\n \"# 2. run `make deps_table_update``\",\n \"deps = {\",\n entries,\n \"}\",\n \"\",\n ]\n target = \"src/transformers/dependency_versions_table.py\"\n print(f\"updating {target}\")\n with open(target, \"w\", encoding=\"utf-8\", newline=\"\\n\") as f:\n f.write(\"\\n\".join(content))\n\n\nextras = {}\n\nextras[\"ja\"] = deps_list(\"fugashi\", \"ipadic\", \"unidic_lite\", \"unidic\", \"sudachipy\", \"sudachidict_core\", \"rhoknp\")\nextras[\"sklearn\"] = deps_list(\"scikit-learn\")\n\nextras[\"tf\"] = deps_list(\"tensorflow\", \"onnxconverter-common\", \"tf2onnx\", \"tensorflow-text\", \"keras-nlp\")\nextras[\"tf-cpu\"] = deps_list(\n \"keras\",\n \"tensorflow-cpu\",\n \"onnxconverter-common\",\n \"tf2onnx\",\n \"tensorflow-text\",\n \"keras-nlp\",\n \"tensorflow-probability\",\n)\n\nextras[\"torch\"] = deps_list(\"torch\", \"accelerate\")\nextras[\"accelerate\"] = deps_list(\"accelerate\")\n\nif os.name == \"nt\": # windows\n extras[\"retrieval\"] = deps_list(\"datasets\") # faiss is not supported on windows\n extras[\"flax\"] = [] # jax is not supported on windows\nelse:\n extras[\"retrieval\"] = deps_list(\"faiss-cpu\", \"datasets\")\n extras[\"flax\"] = deps_list(\"jax\", \"jaxlib\", \"flax\", \"optax\", \"scipy\")\n\nextras[\"tokenizers\"] = deps_list(\"tokenizers\")\nextras[\"ftfy\"] = deps_list(\"ftfy\")\nextras[\"onnxruntime\"] = deps_list(\"onnxruntime\", \"onnxruntime-tools\")\nextras[\"onnx\"] = deps_list(\"onnxconverter-common\", \"tf2onnx\") + extras[\"onnxruntime\"]\nextras[\"modelcreation\"] = deps_list(\"cookiecutter\")\n\nextras[\"sagemaker\"] = deps_list(\"sagemaker\")\nextras[\"deepspeed\"] = deps_list(\"deepspeed\") + extras[\"accelerate\"]\nextras[\"optuna\"] = deps_list(\"optuna\")\nextras[\"ray\"] = deps_list(\"ray[tune]\")\nextras[\"sigopt\"] = deps_list(\"sigopt\")\n\nextras[\"integrations\"] = extras[\"optuna\"] + extras[\"ray\"] + extras[\"sigopt\"]\n\nextras[\"serving\"] = deps_list(\"pydantic\", \"uvicorn\", \"fastapi\", \"starlette\")\nextras[\"audio\"] = deps_list(\"librosa\", \"pyctcdecode\", \"phonemizer\", \"kenlm\")\n# `pip install \".[speech]\"` is deprecated and `pip install \".[torch-speech]\"` should be used instead\nextras[\"speech\"] = deps_list(\"torchaudio\") + extras[\"audio\"]\nextras[\"torch-speech\"] = deps_list(\"torchaudio\") + extras[\"audio\"]\nextras[\"tf-speech\"] = extras[\"audio\"]\nextras[\"flax-speech\"] = extras[\"audio\"]\nextras[\"vision\"] = deps_list(\"Pillow\")\nextras[\"timm\"] = deps_list(\"timm\")\nextras[\"torch-vision\"] = deps_list(\"torchvision\") + extras[\"vision\"]\nextras[\"natten\"] = deps_list(\"natten\")\nextras[\"codecarbon\"] = deps_list(\"codecarbon\")\nextras[\"video\"] = deps_list(\"av\")\n\nextras[\"sentencepiece\"] = deps_list(\"sentencepiece\", \"protobuf\")\nextras[\"tiktoken\"] = deps_list(\"tiktoken\", \"blobfile\")\nextras[\"testing\"] = (\n deps_list(\n \"pytest\",\n \"pytest-rich\",\n \"pytest-xdist\",\n \"timeout-decorator\",\n \"parameterized\",\n \"psutil\",\n \"datasets\",\n \"dill\",\n \"evaluate\",\n \"pytest-timeout\",\n \"ruff\",\n \"sacrebleu\",\n \"rouge-score\",\n \"nltk\",\n \"GitPython\",\n \"sacremoses\",\n \"rjieba\",\n \"beautifulsoup4\",\n \"tensorboard\",\n \"pydantic\",\n \"sentencepiece\",\n )\n + extras[\"retrieval\"]\n + extras[\"modelcreation\"]\n)\n\nextras[\"deepspeed-testing\"] = extras[\"deepspeed\"] + extras[\"testing\"] + extras[\"optuna\"] + extras[\"sentencepiece\"]\nextras[\"ruff\"] = deps_list(\"ruff\")\nextras[\"quality\"] = deps_list(\"datasets\", \"isort\", \"ruff\", \"GitPython\", \"urllib3\", \"libcst\", \"rich\")\n\nextras[\"all\"] = (\n extras[\"tf\"]\n + extras[\"torch\"]\n + extras[\"flax\"]\n + extras[\"sentencepiece\"]\n + extras[\"tokenizers\"]\n + extras[\"torch-speech\"]\n + extras[\"vision\"]\n + extras[\"integrations\"]\n + extras[\"timm\"]\n + extras[\"torch-vision\"]\n + extras[\"codecarbon\"]\n + extras[\"accelerate\"]\n + extras[\"video\"]\n)\n\n\nextras[\"dev-torch\"] = (\n extras[\"testing\"]\n + extras[\"torch\"]\n + extras[\"sentencepiece\"]\n + extras[\"tokenizers\"]\n + extras[\"torch-speech\"]\n + extras[\"vision\"]\n + extras[\"integrations\"]\n + extras[\"timm\"]\n + extras[\"torch-vision\"]\n + extras[\"codecarbon\"]\n + extras[\"quality\"]\n + extras[\"ja\"]\n + extras[\"sklearn\"]\n + extras[\"modelcreation\"]\n + extras[\"onnxruntime\"]\n)\nextras[\"dev-tensorflow\"] = (\n extras[\"testing\"]\n + extras[\"tf\"]\n + extras[\"sentencepiece\"]\n + extras[\"tokenizers\"]\n + extras[\"vision\"]\n + extras[\"quality\"]\n + extras[\"sklearn\"]\n + extras[\"modelcreation\"]\n + extras[\"onnx\"]\n + extras[\"tf-speech\"]\n)\nextras[\"dev\"] = (\n extras[\"all\"] + extras[\"testing\"] + extras[\"quality\"] + extras[\"ja\"] + extras[\"sklearn\"] + extras[\"modelcreation\"]\n)\n\nextras[\"torchhub\"] = deps_list(\n \"filelock\",\n \"huggingface-hub\",\n \"importlib_metadata\",\n \"numpy\",\n \"packaging\",\n \"protobuf\",\n \"regex\",\n \"requests\",\n \"sentencepiece\",\n \"torch\",\n \"tokenizers\",\n \"tqdm\",\n)\n\nextras[\"agents\"] = deps_list(\n \"diffusers\", \"accelerate\", \"datasets\", \"torch\", \"sentencepiece\", \"opencv-python\", \"Pillow\"\n)\n\nextras[\"benchmark\"] = deps_list(\"optimum-benchmark\")\n\n# when modifying the following list, make sure to update src/transformers/dependency_versions_check.py\ninstall_requires = [\n deps[\"filelock\"], # filesystem locks, e.g., to prevent parallel downloads\n deps[\"huggingface-hub\"],\n deps[\"numpy\"],\n deps[\"packaging\"], # utilities from PyPA to e.g., compare versions\n deps[\"pyyaml\"], # used for the model cards metadata\n deps[\"regex\"], # for OpenAI GPT\n deps[\"requests\"], # for downloading models over HTTPS\n deps[\"tokenizers\"],\n deps[\"safetensors\"],\n deps[\"tqdm\"], # progress bars in model download and training scripts\n]\n\nsetup(\n name=\"transformers\",\n version=\"4.47.0.dev0\", # expected format is one of x.y.z.dev0, or x.y.z.rc1 or x.y.z (no to dashes, yes to dots)\n author=\"The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)\",\n author_email=\"transformers@huggingface.co\",\n description=\"State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow\",\n long_description=open(\"README.md\", \"r\", encoding=\"utf-8\").read(),\n long_description_content_type=\"text/markdown\",\n keywords=\"NLP vision speech deep learning transformer pytorch tensorflow jax BERT GPT-2 Wav2Vec2 ViT\",\n license=\"Apache 2.0 License\",\n url=\"https://github.com/huggingface/transformers\",\n package_dir={\"\": \"src\"},\n packages=find_packages(\"src\"),\n include_package_data=True,\n package_data={\"\": [\"**/*.cu\", \"**/*.cpp\", \"**/*.cuh\", \"**/*.h\", \"**/*.pyx\"]},\n zip_safe=False,\n extras_require=extras,\n entry_points={\"console_scripts\": [\"transformers-cli=transformers.commands.transformers_cli:main\"]},\n python_requires=\">=3.9.0\",\n install_requires=list(install_requires),\n classifiers=[\n \"Development Status :: 5 - Production/Stable\",\n \"Intended Audience :: Developers\",\n \"Intended Audience :: Education\",\n \"Intended Audience :: Science/Research\",\n \"License :: OSI Approved :: Apache Software License\",\n \"Operating System :: OS Independent\",\n \"Programming Language :: Python :: 3\",\n \"Programming Language :: Python :: 3.9\",\n \"Programming Language :: Python :: 3.10\",\n \"Topic :: Scientific/Engineering :: Artificial Intelligence\",\n ],\n cmdclass={\"deps_table_update\": DepsTableUpdateCommand},\n)\n\nextras[\"tests_torch\"] = deps_list()\nextras[\"tests_tf\"] = deps_list()\nextras[\"tests_flax\"] = deps_list()\nextras[\"tests_torch_and_tf\"] = deps_list()\nextras[\"tests_torch_and_flax\"] = deps_list()\nextras[\"tests_hub\"] = deps_list()\nextras[\"tests_pipelines_torch\"] = deps_list()\nextras[\"tests_pipelines_tf\"] = deps_list()\nextras[\"tests_onnx\"] = deps_list()\nextras[\"tests_examples_torch\"] = deps_list()\nextras[\"tests_examples_tf\"] = deps_list()\nextras[\"tests_custom_tokenizers\"] = deps_list()\nextras[\"tests_exotic_models\"] = deps_list()\nextras[\"consistency\"] = deps_list()\n" | |
| } | |
| ] | |
| }, | |
| { | |
| "url": "https://github.com/pytorch/pytorch", | |
| "files": [ | |
| { | |
| "name": "setup.py", | |
| "content": "# Welcome to the PyTorch setup.py.\n# Environment variables you are probably interested in:\n#\n# DEBUG\n# build with -O0 and -g (debug symbols)\n#\n# REL_WITH_DEB_INFO\n# build with optimizations and -g (debug symbols)\n#\n# USE_CUSTOM_DEBINFO=\"path/to/file1.cpp;path/to/file2.cpp\"\n# build with debug info only for specified files\n#\n# MAX_JOBS\n# maximum number of compile jobs we should use to compile your code\n#\n# USE_CUDA=0\n# disables CUDA build\n#\n# CFLAGS\n# flags to apply to both C and C++ files to be compiled (a quirk of setup.py\n# which we have faithfully adhered to in our build system is that CFLAGS\n# also applies to C++ files (unless CXXFLAGS is set), in contrast to the\n# default behavior of autogoo and cmake build systems.)\n#\n# CC\n# the C/C++ compiler to use\n#\n# Environment variables for feature toggles:\n#\n# DEBUG_CUDA=1\n# if used in conjunction with DEBUG or REL_WITH_DEB_INFO, will also\n# build CUDA kernels with -lineinfo --source-in-ptx. Note that\n# on CUDA 12 this may cause nvcc to OOM, so this is disabled by default.\n\n# USE_CUDNN=0\n# disables the cuDNN build\n#\n# USE_CUSPARSELT=0\n# disables the cuSPARSELt build\n#\n# USE_CUDSS=0\n# disables the cuDSS build\n#\n# USE_CUFILE=0\n# disables the cuFile build\n#\n# USE_FBGEMM=0\n# disables the FBGEMM build\n#\n# USE_KINETO=0\n# disables usage of libkineto library for profiling\n#\n# USE_NUMPY=0\n# disables the NumPy build\n#\n# BUILD_TEST=0\n# disables the test build\n#\n# USE_MKLDNN=0\n# disables use of MKLDNN\n#\n# USE_MKLDNN_ACL\n# enables use of Compute Library backend for MKLDNN on Arm;\n# USE_MKLDNN must be explicitly enabled.\n#\n# MKLDNN_CPU_RUNTIME\n# MKL-DNN threading mode: TBB or OMP (default)\n#\n# USE_STATIC_MKL\n# Prefer to link with MKL statically - Unix only\n# USE_ITT=0\n# disable use of Intel(R) VTune Profiler's ITT functionality\n#\n# USE_NNPACK=0\n# disables NNPACK build\n#\n# USE_DISTRIBUTED=0\n# disables distributed (c10d, gloo, mpi, etc.) build\n#\n# USE_TENSORPIPE=0\n# disables distributed Tensorpipe backend build\n#\n# USE_GLOO=0\n# disables distributed gloo backend build\n#\n# USE_MPI=0\n# disables distributed MPI backend build\n#\n# USE_SYSTEM_NCCL=0\n# disables use of system-wide nccl (we will use our submoduled\n# copy in third_party/nccl)\n#\n# USE_OPENMP=0\n# disables use of OpenMP for parallelization\n#\n# USE_FLASH_ATTENTION=0\n# disables building flash attention for scaled dot product attention\n#\n# USE_MEM_EFF_ATTENTION=0\n# disables building memory efficient attention for scaled dot product attention\n#\n# BUILD_BINARY\n# enables the additional binaries/ build\n#\n# ATEN_AVX512_256=TRUE\n# ATen AVX2 kernels can use 32 ymm registers, instead of the default 16.\n# This option can be used if AVX512 doesn't perform well on a machine.\n# The FBGEMM library also uses AVX512_256 kernels on Xeon D processors,\n# but it also has some (optimized) assembly code.\n#\n# PYTORCH_BUILD_VERSION\n# PYTORCH_BUILD_NUMBER\n# specify the version of PyTorch, rather than the hard-coded version\n# in this file; used when we're building binaries for distribution\n#\n# TORCH_CUDA_ARCH_LIST\n# specify which CUDA architectures to build for.\n# ie `TORCH_CUDA_ARCH_LIST=\"6.0;7.0\"`\n# These are not CUDA versions, instead, they specify what\n# classes of NVIDIA hardware we should generate PTX for.\n#\n# TORCH_XPU_ARCH_LIST\n# specify which XPU architectures to build for.\n# ie `TORCH_XPU_ARCH_LIST=\"ats-m150,lnl-m\"`\n#\n# PYTORCH_ROCM_ARCH\n# specify which AMD GPU targets to build for.\n# ie `PYTORCH_ROCM_ARCH=\"gfx900;gfx906\"`\n#\n# ONNX_NAMESPACE\n# specify a namespace for ONNX built here rather than the hard-coded\n# one in this file; needed to build with other frameworks that share ONNX.\n#\n# BLAS\n# BLAS to be used by Caffe2. Can be MKL, Eigen, ATLAS, FlexiBLAS, or OpenBLAS. If set\n# then the build will fail if the requested BLAS is not found, otherwise\n# the BLAS will be chosen based on what is found on your system.\n#\n# MKL_THREADING\n# MKL threading mode: SEQ, TBB or OMP (default)\n#\n# USE_ROCM_KERNEL_ASSERT=1\n# Enable kernel assert in ROCm platform\n#\n# Environment variables we respect (these environment variables are\n# conventional and are often understood/set by other software.)\n#\n# CUDA_HOME (Linux/OS X)\n# CUDA_PATH (Windows)\n# specify where CUDA is installed; usually /usr/local/cuda or\n# /usr/local/cuda-x.y\n# CUDAHOSTCXX\n# specify a different compiler than the system one to use as the CUDA\n# host compiler for nvcc.\n#\n# CUDA_NVCC_EXECUTABLE\n# Specify a NVCC to use. This is used in our CI to point to a cached nvcc\n#\n# CUDNN_LIB_DIR\n# CUDNN_INCLUDE_DIR\n# CUDNN_LIBRARY\n# specify where cuDNN is installed\n#\n# MIOPEN_LIB_DIR\n# MIOPEN_INCLUDE_DIR\n# MIOPEN_LIBRARY\n# specify where MIOpen is installed\n#\n# NCCL_ROOT\n# NCCL_LIB_DIR\n# NCCL_INCLUDE_DIR\n# specify where nccl is installed\n#\n# ACL_ROOT_DIR\n# specify where Compute Library is installed\n#\n# LIBRARY_PATH\n# LD_LIBRARY_PATH\n# we will search for libraries in these paths\n#\n# ATEN_THREADING\n# ATen parallel backend to use for intra- and inter-op parallelism\n# possible values:\n# OMP - use OpenMP for intra-op and native backend for inter-op tasks\n# NATIVE - use native thread pool for both intra- and inter-op tasks\n#\n# USE_SYSTEM_LIBS (work in progress)\n# Use system-provided libraries to satisfy the build dependencies.\n# When turned on, the following cmake variables will be toggled as well:\n# USE_SYSTEM_CPUINFO=ON\n# USE_SYSTEM_SLEEF=ON\n# USE_SYSTEM_GLOO=ON\n# BUILD_CUSTOM_PROTOBUF=OFF\n# USE_SYSTEM_EIGEN_INSTALL=ON\n# USE_SYSTEM_FP16=ON\n# USE_SYSTEM_PTHREADPOOL=ON\n# USE_SYSTEM_PSIMD=ON\n# USE_SYSTEM_FXDIV=ON\n# USE_SYSTEM_BENCHMARK=ON\n# USE_SYSTEM_ONNX=ON\n# USE_SYSTEM_XNNPACK=ON\n# USE_SYSTEM_PYBIND11=ON\n# USE_SYSTEM_NCCL=ON\n# USE_SYSTEM_NVTX=ON\n#\n# USE_MIMALLOC\n# Static link mimalloc into C10, and use mimalloc in alloc_cpu & alloc_free.\n# By default, It is only enabled on Windows.\n#\n# USE_PRIORITIZED_TEXT_FOR_LD\n# Uses prioritized text form cmake/prioritized_text.txt for LD\n#\n# BUILD_LIBTORCH_WHL\n# Builds libtorch.so and its dependencies as a wheel\n#\n# BUILD_PYTHON_ONLY\n# Builds pytorch as a wheel using libtorch.so from a seperate wheel\n\nimport os\nimport sys\n\n\nif sys.platform == \"win32\" and sys.maxsize.bit_length() == 31:\n print(\n \"32-bit Windows Python runtime is not supported. Please switch to 64-bit Python.\"\n )\n sys.exit(-1)\n\nimport platform\n\n\nBUILD_LIBTORCH_WHL = os.getenv(\"BUILD_LIBTORCH_WHL\", \"0\") == \"1\"\nBUILD_PYTHON_ONLY = os.getenv(\"BUILD_PYTHON_ONLY\", \"0\") == \"1\"\n\npython_min_version = (3, 8, 0)\npython_min_version_str = \".\".join(map(str, python_min_version))\nif sys.version_info < python_min_version:\n print(\n f\"You are using Python {platform.python_version()}. Python >={python_min_version_str} is required.\"\n )\n sys.exit(-1)\n\nimport filecmp\nimport glob\nimport importlib\nimport importlib.util\nimport json\nimport shutil\nimport subprocess\nimport sysconfig\nimport time\nfrom collections import defaultdict\n\nimport setuptools.command.build_ext\nimport setuptools.command.install\nimport setuptools.command.sdist\nfrom setuptools import Extension, find_packages, setup\nfrom setuptools.dist import Distribution\nfrom tools.build_pytorch_libs import build_caffe2\nfrom tools.generate_torch_version import get_torch_version\nfrom tools.setup_helpers.cmake import CMake\nfrom tools.setup_helpers.env import build_type, IS_DARWIN, IS_LINUX, IS_WINDOWS\nfrom tools.setup_helpers.generate_linker_script import gen_linker_script\n\n\ndef _get_package_path(package_name):\n spec = importlib.util.find_spec(package_name)\n if spec:\n # The package might be a namespace package, so get_data may fail\n try:\n loader = spec.loader\n if loader is not None:\n file_path = loader.get_filename() # type: ignore[attr-defined]\n return os.path.dirname(file_path)\n except AttributeError:\n pass\n return None\n\n\n# set up appropriate env variables\nif BUILD_LIBTORCH_WHL:\n # Set up environment variables for ONLY building libtorch.so and not libtorch_python.so\n # functorch is not supported without python\n os.environ[\"BUILD_FUNCTORCH\"] = \"OFF\"\n\n\nif BUILD_PYTHON_ONLY:\n os.environ[\"BUILD_LIBTORCHLESS\"] = \"ON\"\n os.environ[\"LIBTORCH_LIB_PATH\"] = f\"{_get_package_path('torch')}/lib\"\n\n################################################################################\n# Parameters parsed from environment\n################################################################################\n\nVERBOSE_SCRIPT = True\nRUN_BUILD_DEPS = True\n# see if the user passed a quiet flag to setup.py arguments and respect\n# that in our parts of the build\nEMIT_BUILD_WARNING = False\nRERUN_CMAKE = False\nCMAKE_ONLY = False\nfiltered_args = []\nfor i, arg in enumerate(sys.argv):\n if arg == \"--cmake\":\n RERUN_CMAKE = True\n continue\n if arg == \"--cmake-only\":\n # Stop once cmake terminates. Leave users a chance to adjust build\n # options.\n CMAKE_ONLY = True\n continue\n if arg == \"rebuild\" or arg == \"build\":\n arg = \"build\" # rebuild is gone, make it build\n EMIT_BUILD_WARNING = True\n if arg == \"--\":\n filtered_args += sys.argv[i:]\n break\n if arg == \"-q\" or arg == \"--quiet\":\n VERBOSE_SCRIPT = False\n if arg in [\"clean\", \"egg_info\", \"sdist\"]:\n RUN_BUILD_DEPS = False\n filtered_args.append(arg)\nsys.argv = filtered_args\n\nif VERBOSE_SCRIPT:\n\n def report(*args):\n print(*args)\n\nelse:\n\n def report(*args):\n pass\n\n # Make distutils respect --quiet too\n setuptools.distutils.log.warn = report\n\n# Constant known variables used throughout this file\ncwd = os.path.dirname(os.path.abspath(__file__))\nlib_path = os.path.join(cwd, \"torch\", \"lib\")\nthird_party_path = os.path.join(cwd, \"third_party\")\ncaffe2_build_dir = os.path.join(cwd, \"build\")\n\n# CMAKE: full path to python library\nif IS_WINDOWS:\n cmake_python_library = \"{}/libs/python{}.lib\".format(\n sysconfig.get_config_var(\"prefix\"), sysconfig.get_config_var(\"VERSION\")\n )\n # Fix virtualenv builds\n if not os.path.exists(cmake_python_library):\n cmake_python_library = \"{}/libs/python{}.lib\".format(\n sys.base_prefix, sysconfig.get_config_var(\"VERSION\")\n )\nelse:\n cmake_python_library = \"{}/{}\".format(\n sysconfig.get_config_var(\"LIBDIR\"), sysconfig.get_config_var(\"INSTSONAME\")\n )\ncmake_python_include_dir = sysconfig.get_path(\"include\")\n\n\n################################################################################\n# Version, create_version_file, and package_name\n################################################################################\n\npackage_name = os.getenv(\"TORCH_PACKAGE_NAME\", \"torch\")\nLIBTORCH_PKG_NAME = os.getenv(\"LIBTORCH_PACKAGE_NAME\", \"torch_no_python\")\nif BUILD_LIBTORCH_WHL:\n package_name = LIBTORCH_PKG_NAME\n\n\npackage_type = os.getenv(\"PACKAGE_TYPE\", \"wheel\")\nversion = get_torch_version()\nreport(f\"Building wheel {package_name}-{version}\")\n\ncmake = CMake()\n\n\ndef get_submodule_folders():\n git_modules_path = os.path.join(cwd, \".gitmodules\")\n default_modules_path = [\n os.path.join(third_party_path, name)\n for name in [\n \"gloo\",\n \"cpuinfo\",\n \"onnx\",\n \"fbgemm\",\n \"cutlass\",\n ]\n ]\n if not os.path.exists(git_modules_path):\n return default_modules_path\n with open(git_modules_path) as f:\n return [\n os.path.join(cwd, line.split(\"=\", 1)[1].strip())\n for line in f\n if line.strip().startswith(\"path\")\n ]\n\n\ndef check_submodules():\n def check_for_files(folder, files):\n if not any(os.path.exists(os.path.join(folder, f)) for f in files):\n report(\"Could not find any of {} in {}\".format(\", \".join(files), folder))\n report(\"Did you run 'git submodule update --init --recursive'?\")\n sys.exit(1)\n\n def not_exists_or_empty(folder):\n return not os.path.exists(folder) or (\n os.path.isdir(folder) and len(os.listdir(folder)) == 0\n )\n\n if bool(os.getenv(\"USE_SYSTEM_LIBS\", False)):\n return\n folders = get_submodule_folders()\n # If none of the submodule folders exists, try to initialize them\n if all(not_exists_or_empty(folder) for folder in folders):\n try:\n print(\" --- Trying to initialize submodules\")\n start = time.time()\n subprocess.check_call(\n [\"git\", \"submodule\", \"update\", \"--init\", \"--recursive\"], cwd=cwd\n )\n end = time.time()\n print(f\" --- Submodule initialization took {end - start:.2f} sec\")\n except Exception:\n print(\" --- Submodule initalization failed\")\n print(\"Please run:\\n\\tgit submodule update --init --recursive\")\n sys.exit(1)\n for folder in folders:\n check_for_files(\n folder,\n [\n \"CMakeLists.txt\",\n \"Makefile\",\n \"setup.py\",\n \"LICENSE\",\n \"LICENSE.md\",\n \"LICENSE.txt\",\n ],\n )\n check_for_files(\n os.path.join(third_party_path, \"fbgemm\", \"third_party\", \"asmjit\"),\n [\"CMakeLists.txt\"],\n )\n check_for_files(\n os.path.join(third_party_path, \"onnx\", \"third_party\", \"benchmark\"),\n [\"CMakeLists.txt\"],\n )\n\n\n# Windows has very bad support for symbolic links.\n# Instead of using symlinks, we're going to copy files over\ndef mirror_files_into_torchgen():\n # (new_path, orig_path)\n # Directories are OK and are recursively mirrored.\n paths = [\n (\n \"torchgen/packaged/ATen/native/native_functions.yaml\",\n \"aten/src/ATen/native/native_functions.yaml\",\n ),\n (\"torchgen/packaged/ATen/native/tags.yaml\", \"aten/src/ATen/native/tags.yaml\"),\n (\"torchgen/packaged/ATen/templates\", \"aten/src/ATen/templates\"),\n (\"torchgen/packaged/autograd\", \"tools/autograd\"),\n (\"torchgen/packaged/autograd/templates\", \"tools/autograd/templates\"),\n ]\n for new_path, orig_path in paths:\n # Create the dirs involved in new_path if they don't exist\n if not os.path.exists(new_path):\n os.makedirs(os.path.dirname(new_path), exist_ok=True)\n\n # Copy the files from the orig location to the new location\n if os.path.isfile(orig_path):\n shutil.copyfile(orig_path, new_path)\n continue\n if os.path.isdir(orig_path):\n if os.path.exists(new_path):\n # copytree fails if the tree exists already, so remove it.\n shutil.rmtree(new_path)\n shutil.copytree(orig_path, new_path)\n continue\n raise RuntimeError(\"Check the file paths in `mirror_files_into_torchgen()`\")\n\n\n# all the work we need to do _before_ setup runs\ndef build_deps():\n report(\"-- Building version \" + version)\n\n check_submodules()\n check_pydep(\"yaml\", \"pyyaml\")\n build_python = not BUILD_LIBTORCH_WHL\n build_caffe2(\n version=version,\n cmake_python_library=cmake_python_library,\n build_python=build_python,\n rerun_cmake=RERUN_CMAKE,\n cmake_only=CMAKE_ONLY,\n cmake=cmake,\n )\n\n if CMAKE_ONLY:\n report(\n 'Finished running cmake. Run \"ccmake build\" or '\n '\"cmake-gui build\" to adjust build options and '\n '\"python setup.py install\" to build.'\n )\n sys.exit()\n\n # Use copies instead of symbolic files.\n # Windows has very poor support for them.\n sym_files = [\n \"tools/shared/_utils_internal.py\",\n \"torch/utils/benchmark/utils/valgrind_wrapper/callgrind.h\",\n \"torch/utils/benchmark/utils/valgrind_wrapper/valgrind.h\",\n ]\n orig_files = [\n \"torch/_utils_internal.py\",\n \"third_party/valgrind-headers/callgrind.h\",\n \"third_party/valgrind-headers/valgrind.h\",\n ]\n for sym_file, orig_file in zip(sym_files, orig_files):\n same = False\n if os.path.exists(sym_file):\n if filecmp.cmp(sym_file, orig_file):\n same = True\n else:\n os.remove(sym_file)\n if not same:\n shutil.copyfile(orig_file, sym_file)\n\n\n################################################################################\n# Building dependent libraries\n################################################################################\n\nmissing_pydep = \"\"\"\nMissing build dependency: Unable to `import {importname}`.\nPlease install it via `conda install {module}` or `pip install {module}`\n\"\"\".strip()\n\n\ndef check_pydep(importname, module):\n try:\n importlib.import_module(importname)\n except ImportError as e:\n raise RuntimeError(\n missing_pydep.format(importname=importname, module=module)\n ) from e\n\n\nclass build_ext(setuptools.command.build_ext.build_ext):\n def _embed_libomp(self):\n # Copy libiomp5.dylib/libomp.dylib inside the wheel package on MacOS\n lib_dir = os.path.join(self.build_lib, \"torch\", \"lib\")\n libtorch_cpu_path = os.path.join(lib_dir, \"libtorch_cpu.dylib\")\n if not os.path.exists(libtorch_cpu_path):\n return\n # Parse libtorch_cpu load commands\n otool_cmds = (\n subprocess.check_output([\"otool\", \"-l\", libtorch_cpu_path])\n .decode(\"utf-8\")\n .split(\"\\n\")\n )\n rpaths, libs = [], []\n for idx, line in enumerate(otool_cmds):\n if line.strip() == \"cmd LC_LOAD_DYLIB\":\n lib_name = otool_cmds[idx + 2].strip()\n assert lib_name.startswith(\"name \")\n libs.append(lib_name.split(\" \", 1)[1].rsplit(\"(\", 1)[0][:-1])\n\n if line.strip() == \"cmd LC_RPATH\":\n rpath = otool_cmds[idx + 2].strip()\n assert rpath.startswith(\"path \")\n rpaths.append(rpath.split(\" \", 1)[1].rsplit(\"(\", 1)[0][:-1])\n\n omp_lib_name = (\n \"libomp.dylib\" if os.uname().machine == \"arm64\" else \"libiomp5.dylib\"\n )\n omp_rpath_lib_path = os.path.join(\"@rpath\", omp_lib_name)\n if omp_rpath_lib_path not in libs:\n return\n\n # Copy libomp/libiomp5 from rpath locations\n for rpath in rpaths:\n source_lib = os.path.join(rpath, omp_lib_name)\n if not os.path.exists(source_lib):\n continue\n target_lib = os.path.join(self.build_lib, \"torch\", \"lib\", omp_lib_name)\n self.copy_file(source_lib, target_lib)\n # Delete old rpath and add @loader_lib to the rpath\n # This should prevent delocate from attempting to package another instance\n # of OpenMP library in torch wheel as well as loading two libomp.dylib into\n # the address space, as libraries are cached by their unresolved names\n subprocess.check_call(\n [\n \"install_name_tool\",\n \"-rpath\",\n rpath,\n \"@loader_path\",\n libtorch_cpu_path,\n ]\n )\n break\n\n # Copy omp.h from OpenMP_C_FLAGS and copy it into include folder\n omp_cflags = get_cmake_cache_vars()[\"OpenMP_C_FLAGS\"]\n if not omp_cflags:\n return\n for include_dir in [f[2:] for f in omp_cflags.split(\" \") if f.startswith(\"-I\")]:\n omp_h = os.path.join(include_dir, \"omp.h\")\n if not os.path.exists(omp_h):\n continue\n target_omp_h = os.path.join(self.build_lib, \"torch\", \"include\", \"omp.h\")\n self.copy_file(omp_h, target_omp_h)\n break\n\n def run(self):\n # Report build options. This is run after the build completes so # `CMakeCache.txt` exists and we can get an\n # accurate report on what is used and what is not.\n cmake_cache_vars = defaultdict(lambda: False, cmake.get_cmake_cache_variables())\n if cmake_cache_vars[\"USE_NUMPY\"]:\n report(\"-- Building with NumPy bindings\")\n else:\n report(\"-- NumPy not found\")\n if cmake_cache_vars[\"USE_CUDNN\"]:\n report(\n \"-- Detected cuDNN at \"\n + cmake_cache_vars[\"CUDNN_LIBRARY\"]\n + \", \"\n + cmake_cache_vars[\"CUDNN_INCLUDE_DIR\"]\n )\n else:\n report(\"-- Not using cuDNN\")\n if cmake_cache_vars[\"USE_CUDA\"]:\n report(\"-- Detected CUDA at \" + cmake_cache_vars[\"CUDA_TOOLKIT_ROOT_DIR\"])\n else:\n report(\"-- Not using CUDA\")\n if cmake_cache_vars[\"USE_XPU\"]:\n report(\"-- Detected XPU runtime at \" + cmake_cache_vars[\"SYCL_LIBRARY_DIR\"])\n else:\n report(\"-- Not using XPU\")\n if cmake_cache_vars[\"USE_MKLDNN\"]:\n report(\"-- Using MKLDNN\")\n if cmake_cache_vars[\"USE_MKLDNN_ACL\"]:\n report(\"-- Using Compute Library for the Arm architecture with MKLDNN\")\n else:\n report(\n \"-- Not using Compute Library for the Arm architecture with MKLDNN\"\n )\n if cmake_cache_vars[\"USE_MKLDNN_CBLAS\"]:\n report(\"-- Using CBLAS in MKLDNN\")\n else:\n report(\"-- Not using CBLAS in MKLDNN\")\n else:\n report(\"-- Not using MKLDNN\")\n if cmake_cache_vars[\"USE_NCCL\"] and cmake_cache_vars[\"USE_SYSTEM_NCCL\"]:\n report(\n \"-- Using system provided NCCL library at {}, {}\".format(\n cmake_cache_vars[\"NCCL_LIBRARIES\"],\n cmake_cache_vars[\"NCCL_INCLUDE_DIRS\"],\n )\n )\n elif cmake_cache_vars[\"USE_NCCL\"]:\n report(\"-- Building NCCL library\")\n else:\n report(\"-- Not using NCCL\")\n if cmake_cache_vars[\"USE_DISTRIBUTED\"]:\n if IS_WINDOWS:\n report(\"-- Building without distributed package\")\n else:\n report(\"-- Building with distributed package: \")\n report(\n \" -- USE_TENSORPIPE={}\".format(cmake_cache_vars[\"USE_TENSORPIPE\"])\n )\n report(\" -- USE_GLOO={}\".format(cmake_cache_vars[\"USE_GLOO\"]))\n report(\" -- USE_MPI={}\".format(cmake_cache_vars[\"USE_OPENMPI\"]))\n else:\n report(\"-- Building without distributed package\")\n if cmake_cache_vars[\"STATIC_DISPATCH_BACKEND\"]:\n report(\n \"-- Using static dispatch with backend {}\".format(\n cmake_cache_vars[\"STATIC_DISPATCH_BACKEND\"]\n )\n )\n if cmake_cache_vars[\"USE_LIGHTWEIGHT_DISPATCH\"]:\n report(\"-- Using lightweight dispatch\")\n if cmake_cache_vars[\"BUILD_EXECUTORCH\"]:\n report(\"-- Building Executorch\")\n\n if cmake_cache_vars[\"USE_ITT\"]:\n report(\"-- Using ITT\")\n else:\n report(\"-- Not using ITT\")\n\n # Do not use clang to compile extensions if `-fstack-clash-protection` is defined\n # in system CFLAGS\n c_flags = str(os.getenv(\"CFLAGS\", \"\"))\n if (\n IS_LINUX\n and \"-fstack-clash-protection\" in c_flags\n and \"clang\" in os.environ.get(\"CC\", \"\")\n ):\n os.environ[\"CC\"] = str(os.environ[\"CC\"])\n\n # It's an old-style class in Python 2.7...\n setuptools.command.build_ext.build_ext.run(self)\n\n if IS_DARWIN and package_type != \"conda\":\n self._embed_libomp()\n\n # Copy the essential export library to compile C++ extensions.\n if IS_WINDOWS:\n build_temp = self.build_temp\n\n ext_filename = self.get_ext_filename(\"_C\")\n lib_filename = \".\".join(ext_filename.split(\".\")[:-1]) + \".lib\"\n\n export_lib = os.path.join(\n build_temp, \"torch\", \"csrc\", lib_filename\n ).replace(\"\\\\\", \"/\")\n\n build_lib = self.build_lib\n\n target_lib = os.path.join(build_lib, \"torch\", \"lib\", \"_C.lib\").replace(\n \"\\\\\", \"/\"\n )\n\n # Create \"torch/lib\" directory if not exists.\n # (It is not created yet in \"develop\" mode.)\n target_dir = os.path.dirname(target_lib)\n if not os.path.exists(target_dir):\n os.makedirs(target_dir)\n\n self.copy_file(export_lib, target_lib)\n\n def build_extensions(self):\n self.create_compile_commands()\n # The caffe2 extensions are created in\n # tmp_install/lib/pythonM.m/site-packages/caffe2/python/\n # and need to be copied to build/lib.linux.... , which will be a\n # platform dependent build folder created by the \"build\" command of\n # setuptools. Only the contents of this folder are installed in the\n # \"install\" command by default.\n # We only make this copy for Caffe2's pybind extensions\n caffe2_pybind_exts = [\n \"caffe2.python.caffe2_pybind11_state\",\n \"caffe2.python.caffe2_pybind11_state_gpu\",\n \"caffe2.python.caffe2_pybind11_state_hip\",\n ]\n if BUILD_LIBTORCH_WHL:\n caffe2_pybind_exts = []\n i = 0\n while i < len(self.extensions):\n ext = self.extensions[i]\n if ext.name not in caffe2_pybind_exts:\n i += 1\n continue\n fullname = self.get_ext_fullname(ext.name)\n filename = self.get_ext_filename(fullname)\n report(f\"\\nCopying extension {ext.name}\")\n\n relative_site_packages = (\n sysconfig.get_path(\"purelib\")\n .replace(sysconfig.get_path(\"data\"), \"\")\n .lstrip(os.path.sep)\n )\n src = os.path.join(\"torch\", relative_site_packages, filename)\n if not os.path.exists(src):\n report(f\"{src} does not exist\")\n del self.extensions[i]\n else:\n dst = os.path.join(os.path.realpath(self.build_lib), filename)\n report(f\"Copying {ext.name} from {src} to {dst}\")\n dst_dir = os.path.dirname(dst)\n if not os.path.exists(dst_dir):\n os.makedirs(dst_dir)\n self.copy_file(src, dst)\n i += 1\n\n # Copy functorch extension\n for i, ext in enumerate(self.extensions):\n if ext.name != \"functorch._C\":\n continue\n fullname = self.get_ext_fullname(ext.name)\n filename = self.get_ext_filename(fullname)\n fileext = os.path.splitext(filename)[1]\n src = os.path.join(os.path.dirname(filename), \"functorch\" + fileext)\n dst = os.path.join(os.path.realpath(self.build_lib), filename)\n if os.path.exists(src):\n report(f\"Copying {ext.name} from {src} to {dst}\")\n dst_dir = os.path.dirname(dst)\n if not os.path.exists(dst_dir):\n os.makedirs(dst_dir)\n self.copy_file(src, dst)\n\n setuptools.command.build_ext.build_ext.build_extensions(self)\n\n def get_outputs(self):\n outputs = setuptools.command.build_ext.build_ext.get_outputs(self)\n outputs.append(os.path.join(self.build_lib, \"caffe2\"))\n report(f\"setup.py::get_outputs returning {outputs}\")\n return outputs\n\n def create_compile_commands(self):\n def load(filename):\n with open(filename) as f:\n return json.load(f)\n\n ninja_files = glob.glob(\"build/*compile_commands.json\")\n cmake_files = glob.glob(\"torch/lib/build/*/compile_commands.json\")\n all_commands = [entry for f in ninja_files + cmake_files for entry in load(f)]\n\n # cquery does not like c++ compiles that start with gcc.\n # It forgets to include the c++ header directories.\n # We can work around this by replacing the gcc calls that python\n # setup.py generates with g++ calls instead\n for command in all_commands:\n if command[\"command\"].startswith(\"gcc \"):\n command[\"command\"] = \"g++ \" + command[\"command\"][4:]\n\n new_contents = json.dumps(all_commands, indent=2)\n contents = \"\"\n if os.path.exists(\"compile_commands.json\"):\n with open(\"compile_commands.json\") as f:\n contents = f.read()\n if contents != new_contents:\n with open(\"compile_commands.json\", \"w\") as f:\n f.write(new_contents)\n\n\nclass concat_license_files:\n \"\"\"Merge LICENSE and LICENSES_BUNDLED.txt as a context manager\n\n LICENSE is the main PyTorch license, LICENSES_BUNDLED.txt is auto-generated\n from all the licenses found in ./third_party/. We concatenate them so there\n is a single license file in the sdist and wheels with all of the necessary\n licensing info.\n \"\"\"\n\n def __init__(self, include_files=False):\n self.f1 = \"LICENSE\"\n self.f2 = \"third_party/LICENSES_BUNDLED.txt\"\n self.include_files = include_files\n\n def __enter__(self):\n \"\"\"Concatenate files\"\"\"\n\n old_path = sys.path\n sys.path.append(third_party_path)\n try:\n from build_bundled import create_bundled\n finally:\n sys.path = old_path\n\n with open(self.f1) as f1:\n self.bsd_text = f1.read()\n\n with open(self.f1, \"a\") as f1:\n f1.write(\"\\n\\n\")\n create_bundled(\n os.path.relpath(third_party_path), f1, include_files=self.include_files\n )\n\n def __exit__(self, exception_type, exception_value, traceback):\n \"\"\"Restore content of f1\"\"\"\n with open(self.f1, \"w\") as f:\n f.write(self.bsd_text)\n\n\ntry:\n from wheel.bdist_wheel import bdist_wheel\nexcept ImportError:\n # This is useful when wheel is not installed and bdist_wheel is not\n # specified on the command line. If it _is_ specified, parsing the command\n # line will fail before wheel_concatenate is needed\n wheel_concatenate = None\nelse:\n # Need to create the proper LICENSE.txt for the wheel\n class wheel_concatenate(bdist_wheel):\n \"\"\"check submodules on sdist to prevent incomplete tarballs\"\"\"\n\n def run(self):\n with concat_license_files(include_files=True):\n super().run()\n\n def write_wheelfile(self, *args, **kwargs):\n super().write_wheelfile(*args, **kwargs)\n\n if BUILD_LIBTORCH_WHL:\n # Remove extraneneous files in the libtorch wheel\n for root, dirs, files in os.walk(self.bdist_dir):\n for file in files:\n if file.endswith((\".a\", \".so\")) and os.path.isfile(\n os.path.join(self.bdist_dir, file)\n ):\n os.remove(os.path.join(root, file))\n elif file.endswith(\".py\"):\n os.remove(os.path.join(root, file))\n # need an __init__.py file otherwise we wouldn't have a package\n open(os.path.join(self.bdist_dir, \"torch\", \"__init__.py\"), \"w\").close()\n\n\nclass install(setuptools.command.install.install):\n def run(self):\n super().run()\n\n\nclass clean(setuptools.Command):\n user_options = []\n\n def initialize_options(self):\n pass\n\n def finalize_options(self):\n pass\n\n def run(self):\n import glob\n import re\n\n with open(\".gitignore\") as f:\n ignores = f.read()\n pat = re.compile(r\"^#( BEGIN NOT-CLEAN-FILES )?\")\n for wildcard in filter(None, ignores.split(\"\\n\")):\n match = pat.match(wildcard)\n if match:\n if match.group(1):\n # Marker is found and stop reading .gitignore.\n break\n # Ignore lines which begin with '#'.\n else:\n # Don't remove absolute paths from the system\n wildcard = wildcard.lstrip(\"./\")\n\n for filename in glob.glob(wildcard):\n try:\n os.remove(filename)\n except OSError:\n shutil.rmtree(filename, ignore_errors=True)\n\n\nclass sdist(setuptools.command.sdist.sdist):\n def run(self):\n with concat_license_files():\n super().run()\n\n\ndef get_cmake_cache_vars():\n try:\n return defaultdict(lambda: False, cmake.get_cmake_cache_variables())\n except FileNotFoundError:\n # CMakeCache.txt does not exist. Probably running \"python setup.py clean\" over a clean directory.\n return defaultdict(lambda: False)\n\n\ndef configure_extension_build():\n r\"\"\"Configures extension build options according to system environment and user's choice.\n\n Returns:\n The input to parameters ext_modules, cmdclass, packages, and entry_points as required in setuptools.setup.\n \"\"\"\n\n cmake_cache_vars = get_cmake_cache_vars()\n\n ################################################################################\n # Configure compile flags\n ################################################################################\n\n library_dirs = []\n extra_install_requires = []\n\n if IS_WINDOWS:\n # /NODEFAULTLIB makes sure we only link to DLL runtime\n # and matches the flags set for protobuf and ONNX\n extra_link_args = [\"/NODEFAULTLIB:LIBCMT.LIB\"]\n # /MD links against DLL runtime\n # and matches the flags set for protobuf and ONNX\n # /EHsc is about standard C++ exception handling\n extra_compile_args = [\"/MD\", \"/FS\", \"/EHsc\"]\n else:\n extra_link_args = []\n extra_compile_args = [\n \"-Wall\",\n \"-Wextra\",\n \"-Wno-strict-overflow\",\n \"-Wno-unused-parameter\",\n \"-Wno-missing-field-initializers\",\n \"-Wno-unknown-pragmas\",\n # Python 2.6 requires -fno-strict-aliasing, see\n # http://legacy.python.org/dev/peps/pep-3123/\n # We also depend on it in our code (even Python 3).\n \"-fno-strict-aliasing\",\n ]\n\n library_dirs.append(lib_path)\n\n main_compile_args = []\n main_libraries = [\"torch_python\"]\n\n main_link_args = []\n main_sources = [\"torch/csrc/stub.c\"]\n\n if BUILD_LIBTORCH_WHL:\n main_libraries = [\"torch\"]\n main_sources = []\n\n if build_type.is_debug():\n if IS_WINDOWS:\n extra_compile_args.append(\"/Z7\")\n extra_link_args.append(\"/DEBUG:FULL\")\n else:\n extra_compile_args += [\"-O0\", \"-g\"]\n extra_link_args += [\"-O0\", \"-g\"]\n\n if build_type.is_rel_with_deb_info():\n if IS_WINDOWS:\n extra_compile_args.append(\"/Z7\")\n extra_link_args.append(\"/DEBUG:FULL\")\n else:\n extra_compile_args += [\"-g\"]\n extra_link_args += [\"-g\"]\n\n # pypi cuda package that requires installation of cuda runtime, cudnn and cublas\n # should be included in all wheels uploaded to pypi\n pytorch_extra_install_requirements = os.getenv(\n \"PYTORCH_EXTRA_INSTALL_REQUIREMENTS\", \"\"\n )\n if pytorch_extra_install_requirements:\n report(\n f\"pytorch_extra_install_requirements: {pytorch_extra_install_requirements}\"\n )\n extra_install_requires += pytorch_extra_install_requirements.split(\"|\")\n\n # Cross-compile for M1\n if IS_DARWIN:\n macos_target_arch = os.getenv(\"CMAKE_OSX_ARCHITECTURES\", \"\")\n if macos_target_arch in [\"arm64\", \"x86_64\"]:\n macos_sysroot_path = os.getenv(\"CMAKE_OSX_SYSROOT\")\n if macos_sysroot_path is None:\n macos_sysroot_path = (\n subprocess.check_output(\n [\"xcrun\", \"--show-sdk-path\", \"--sdk\", \"macosx\"]\n )\n .decode(\"utf-8\")\n .strip()\n )\n extra_compile_args += [\n \"-arch\",\n macos_target_arch,\n \"-isysroot\",\n macos_sysroot_path,\n ]\n extra_link_args += [\"-arch\", macos_target_arch]\n\n def make_relative_rpath_args(path):\n if IS_DARWIN:\n return [\"-Wl,-rpath,@loader_path/\" + path]\n elif IS_WINDOWS:\n return []\n else:\n return [\"-Wl,-rpath,$ORIGIN/\" + path]\n\n ################################################################################\n # Declare extensions and package\n ################################################################################\n\n extensions = []\n excludes = [\"tools\", \"tools.*\"]\n if not cmake_cache_vars[\"BUILD_CAFFE2\"]:\n excludes.extend([\"caffe2\", \"caffe2.*\"])\n if not cmake_cache_vars[\"BUILD_FUNCTORCH\"]:\n excludes.extend([\"functorch\", \"functorch.*\"])\n packages = find_packages(exclude=excludes)\n C = Extension(\n \"torch._C\",\n libraries=main_libraries,\n sources=main_sources,\n language=\"c\",\n extra_compile_args=main_compile_args + extra_compile_args,\n include_dirs=[],\n library_dirs=library_dirs,\n extra_link_args=extra_link_args\n + main_link_args\n + make_relative_rpath_args(\"lib\"),\n )\n extensions.append(C)\n\n # These extensions are built by cmake and copied manually in build_extensions()\n # inside the build_ext implementation\n if cmake_cache_vars[\"BUILD_CAFFE2\"]:\n extensions.append(\n Extension(name=\"caffe2.python.caffe2_pybind11_state\", sources=[]),\n )\n if cmake_cache_vars[\"USE_CUDA\"]:\n extensions.append(\n Extension(name=\"caffe2.python.caffe2_pybind11_state_gpu\", sources=[]),\n )\n if cmake_cache_vars[\"USE_ROCM\"]:\n extensions.append(\n Extension(name=\"caffe2.python.caffe2_pybind11_state_hip\", sources=[]),\n )\n if cmake_cache_vars[\"BUILD_FUNCTORCH\"]:\n extensions.append(\n Extension(name=\"functorch._C\", sources=[]),\n )\n\n cmdclass = {\n \"bdist_wheel\": wheel_concatenate,\n \"build_ext\": build_ext,\n \"clean\": clean,\n \"install\": install,\n \"sdist\": sdist,\n }\n\n entry_points = {\n \"console_scripts\": [\n \"convert-caffe2-to-onnx = caffe2.python.onnx.bin.conversion:caffe2_to_onnx\",\n \"convert-onnx-to-caffe2 = caffe2.python.onnx.bin.conversion:onnx_to_caffe2\",\n \"torchrun = torch.distributed.run:main\",\n ],\n \"torchrun.logs_specs\": [\n \"default = torch.distributed.elastic.multiprocessing:DefaultLogsSpecs\",\n ],\n }\n\n if cmake_cache_vars[\"USE_DISTRIBUTED\"]:\n # Only enable fr_trace command if distributed is enabled\n entry_points[\"console_scripts\"].append(\n \"torchfrtrace = tools.flight_recorder.fr_trace:main\",\n )\n return extensions, cmdclass, packages, entry_points, extra_install_requires\n\n\n# post run, warnings, printed at the end to make them more visible\nbuild_update_message = \"\"\"\n It is no longer necessary to use the 'build' or 'rebuild' targets\n\n To install:\n $ python setup.py install\n To develop locally:\n $ python setup.py develop\n To force cmake to re-generate native build files (off by default):\n $ python setup.py develop --cmake\n\"\"\"\n\n\ndef print_box(msg):\n lines = msg.split(\"\\n\")\n size = max(len(l) + 1 for l in lines)\n print(\"-\" * (size + 2))\n for l in lines:\n print(\"|{}{}|\".format(l, \" \" * (size - len(l))))\n print(\"-\" * (size + 2))\n\n\ndef main():\n if BUILD_LIBTORCH_WHL and BUILD_PYTHON_ONLY:\n raise RuntimeError(\n \"Conflict: 'BUILD_LIBTORCH_WHL' and 'BUILD_PYTHON_ONLY' can't both be 1. Set one to 0 and rerun.\"\n )\n install_requires = [\n \"filelock\",\n \"typing-extensions>=4.8.0\",\n 'setuptools ; python_version >= \"3.12\"',\n 'sympy==1.13.1 ; python_version >= \"3.9\"',\n \"networkx\",\n \"jinja2\",\n \"fsspec\",\n ]\n\n if BUILD_PYTHON_ONLY:\n install_requires.append(f\"{LIBTORCH_PKG_NAME}=={get_torch_version()}\")\n\n use_prioritized_text = str(os.getenv(\"USE_PRIORITIZED_TEXT_FOR_LD\", \"\"))\n if (\n use_prioritized_text == \"\"\n and platform.system() == \"Linux\"\n and platform.processor() == \"aarch64\"\n ):\n print_box(\n \"\"\"\n WARNING: we strongly recommend enabling linker script optimization for ARM + CUDA.\n To do so please export USE_PRIORITIZED_TEXT_FOR_LD=1\n \"\"\"\n )\n if use_prioritized_text == \"1\" or use_prioritized_text == \"True\":\n gen_linker_script(\n filein=\"cmake/prioritized_text.txt\", fout=\"cmake/linker_script.ld\"\n )\n linker_script_path = os.path.abspath(\"cmake/linker_script.ld\")\n os.environ[\"LDFLAGS\"] = os.getenv(\"LDFLAGS\", \"\") + f\" -T{linker_script_path}\"\n os.environ[\"CFLAGS\"] = (\n os.getenv(\"CFLAGS\", \"\") + \" -ffunction-sections -fdata-sections\"\n )\n os.environ[\"CXXFLAGS\"] = (\n os.getenv(\"CXXFLAGS\", \"\") + \" -ffunction-sections -fdata-sections\"\n )\n\n # Parse the command line and check the arguments before we proceed with\n # building deps and setup. We need to set values so `--help` works.\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = sys.argv[1:]\n try:\n dist.parse_command_line()\n except setuptools.distutils.errors.DistutilsArgError as e:\n print(e)\n sys.exit(1)\n\n mirror_files_into_torchgen()\n if RUN_BUILD_DEPS:\n build_deps()\n\n (\n extensions,\n cmdclass,\n packages,\n entry_points,\n extra_install_requires,\n ) = configure_extension_build()\n install_requires += extra_install_requires\n\n extras_require = {\n \"optree\": [\"optree>=0.13.0\"],\n \"opt-einsum\": [\"opt-einsum>=3.3\"],\n }\n\n # Read in README.md for our long_description\n with open(os.path.join(cwd, \"README.md\"), encoding=\"utf-8\") as f:\n long_description = f.read()\n\n version_range_max = max(sys.version_info[1], 12) + 1\n torch_package_data = [\n \"py.typed\",\n \"bin/*\",\n \"test/*\",\n \"*.pyi\",\n \"_C/*.pyi\",\n \"cuda/*.pyi\",\n \"fx/*.pyi\",\n \"optim/*.pyi\",\n \"autograd/*.pyi\",\n \"jit/*.pyi\",\n \"nn/*.pyi\",\n \"nn/modules/*.pyi\",\n \"nn/parallel/*.pyi\",\n \"utils/data/*.pyi\",\n \"utils/data/datapipes/*.pyi\",\n \"lib/*.pdb\",\n \"lib/*shm*\",\n \"lib/torch_shm_manager\",\n \"lib/*.h\",\n \"include/*.h\",\n \"include/ATen/*.h\",\n \"include/ATen/cpu/*.h\",\n \"include/ATen/cpu/vec/vec256/*.h\",\n \"include/ATen/cpu/vec/vec256/vsx/*.h\",\n \"include/ATen/cpu/vec/vec256/zarch/*.h\",\n \"include/ATen/cpu/vec/vec512/*.h\",\n \"include/ATen/cpu/vec/*.h\",\n \"include/ATen/cpu/vec/sve/*.h\",\n \"include/ATen/core/*.h\",\n \"include/ATen/cuda/*.cuh\",\n \"include/ATen/cuda/*.h\",\n \"include/ATen/cuda/detail/*.cuh\",\n \"include/ATen/cuda/detail/*.h\",\n \"include/ATen/cuda/tunable/*.h\",\n \"include/ATen/cudnn/*.h\",\n \"include/ATen/functorch/*.h\",\n \"include/ATen/ops/*.h\",\n \"include/ATen/hip/*.cuh\",\n \"include/ATen/hip/*.h\",\n \"include/ATen/hip/detail/*.cuh\",\n \"include/ATen/hip/detail/*.h\",\n \"include/ATen/hip/impl/*.h\",\n \"include/ATen/hip/tunable/*.h\",\n \"include/ATen/mps/*.h\",\n \"include/ATen/miopen/*.h\",\n \"include/ATen/detail/*.h\",\n \"include/ATen/native/*.h\",\n \"include/ATen/native/cpu/*.h\",\n \"include/ATen/native/cuda/*.h\",\n \"include/ATen/native/cuda/*.cuh\",\n \"include/ATen/native/hip/*.h\",\n \"include/ATen/native/hip/*.cuh\",\n \"include/ATen/native/mps/*.h\",\n \"include/ATen/native/nested/*.h\",\n \"include/ATen/native/quantized/*.h\",\n \"include/ATen/native/quantized/cpu/*.h\",\n \"include/ATen/native/transformers/*.h\",\n \"include/ATen/native/sparse/*.h\",\n \"include/ATen/native/utils/*.h\",\n \"include/ATen/quantized/*.h\",\n \"include/ATen/xpu/*.h\",\n \"include/ATen/xpu/detail/*.h\",\n \"include/caffe2/serialize/*.h\",\n \"include/c10/*.h\",\n \"include/c10/macros/*.h\",\n \"include/c10/core/*.h\",\n \"include/ATen/core/boxing/*.h\",\n \"include/ATen/core/boxing/impl/*.h\",\n \"include/ATen/core/dispatch/*.h\",\n \"include/ATen/core/op_registration/*.h\",\n \"include/c10/core/impl/*.h\",\n \"include/c10/util/*.h\",\n \"include/c10/cuda/*.h\",\n \"include/c10/cuda/impl/*.h\",\n \"include/c10/hip/*.h\",\n \"include/c10/hip/impl/*.h\",\n \"include/c10/xpu/*.h\",\n \"include/c10/xpu/impl/*.h\",\n \"include/torch/*.h\",\n \"include/torch/csrc/*.h\",\n \"include/torch/csrc/api/include/torch/*.h\",\n \"include/torch/csrc/api/include/torch/data/*.h\",\n \"include/torch/csrc/api/include/torch/data/dataloader/*.h\",\n \"include/torch/csrc/api/include/torch/data/datasets/*.h\",\n \"include/torch/csrc/api/include/torch/data/detail/*.h\",\n \"include/torch/csrc/api/include/torch/data/samplers/*.h\",\n \"include/torch/csrc/api/include/torch/data/transforms/*.h\",\n \"include/torch/csrc/api/include/torch/detail/*.h\",\n \"include/torch/csrc/api/include/torch/detail/ordered_dict.h\",\n \"include/torch/csrc/api/include/torch/nn/*.h\",\n \"include/torch/csrc/api/include/torch/nn/functional/*.h\",\n \"include/torch/csrc/api/include/torch/nn/options/*.h\",\n \"include/torch/csrc/api/include/torch/nn/modules/*.h\",\n \"include/torch/csrc/api/include/torch/nn/modules/container/*.h\",\n \"include/torch/csrc/api/include/torch/nn/parallel/*.h\",\n \"include/torch/csrc/api/include/torch/nn/utils/*.h\",\n \"include/torch/csrc/api/include/torch/optim/*.h\",\n \"include/torch/csrc/api/include/torch/optim/schedulers/*.h\",\n \"include/torch/csrc/api/include/torch/serialize/*.h\",\n \"include/torch/csrc/autograd/*.h\",\n \"include/torch/csrc/autograd/functions/*.h\",\n \"include/torch/csrc/autograd/generated/*.h\",\n \"include/torch/csrc/autograd/utils/*.h\",\n \"include/torch/csrc/cuda/*.h\",\n \"include/torch/csrc/distributed/c10d/*.h\",\n \"include/torch/csrc/distributed/c10d/*.hpp\",\n \"include/torch/csrc/distributed/rpc/*.h\",\n \"include/torch/csrc/distributed/autograd/context/*.h\",\n \"include/torch/csrc/distributed/autograd/functions/*.h\",\n \"include/torch/csrc/distributed/autograd/rpc_messages/*.h\",\n \"include/torch/csrc/dynamo/*.h\",\n \"include/torch/csrc/inductor/*.h\",\n \"include/torch/csrc/inductor/aoti_package/*.h\",\n \"include/torch/csrc/inductor/aoti_runner/*.h\",\n \"include/torch/csrc/inductor/aoti_runtime/*.h\",\n \"include/torch/csrc/inductor/aoti_torch/*.h\",\n \"include/torch/csrc/inductor/aoti_torch/c/*.h\",\n \"include/torch/csrc/inductor/aoti_torch/generated/*.h\",\n \"include/torch/csrc/jit/*.h\",\n \"include/torch/csrc/jit/backends/*.h\",\n \"include/torch/csrc/jit/generated/*.h\",\n \"include/torch/csrc/jit/passes/*.h\",\n \"include/torch/csrc/jit/passes/quantization/*.h\",\n \"include/torch/csrc/jit/passes/utils/*.h\",\n \"include/torch/csrc/jit/runtime/*.h\",\n \"include/torch/csrc/jit/ir/*.h\",\n \"include/torch/csrc/jit/frontend/*.h\",\n \"include/torch/csrc/jit/api/*.h\",\n \"include/torch/csrc/jit/serialization/*.h\",\n \"include/torch/csrc/jit/python/*.h\",\n \"include/torch/csrc/jit/mobile/*.h\",\n \"include/torch/csrc/jit/testing/*.h\",\n \"include/torch/csrc/jit/tensorexpr/*.h\",\n \"include/torch/csrc/jit/tensorexpr/operators/*.h\",\n \"include/torch/csrc/jit/codegen/cuda/*.h\",\n \"include/torch/csrc/onnx/*.h\",\n \"include/torch/csrc/profiler/*.h\",\n \"include/torch/csrc/profiler/orchestration/*.h\",\n \"include/torch/csrc/profiler/standalone/*.h\",\n \"include/torch/csrc/profiler/stubs/*.h\",\n \"include/torch/csrc/profiler/unwind/*.h\",\n \"include/torch/csrc/profiler/python/*.h\",\n \"include/torch/csrc/utils/*.h\",\n \"include/torch/csrc/tensor/*.h\",\n \"include/torch/csrc/lazy/backend/*.h\",\n \"include/torch/csrc/lazy/core/*.h\",\n \"include/torch/csrc/lazy/core/internal_ops/*.h\",\n \"include/torch/csrc/lazy/core/ops/*.h\",\n \"include/torch/csrc/lazy/python/python_util.h\",\n \"include/torch/csrc/lazy/ts_backend/*.h\",\n \"include/torch/csrc/xpu/*.h\",\n \"include/pybind11/*.h\",\n \"include/pybind11/detail/*.h\",\n \"include/pybind11/eigen/*.h\",\n \"include/TH/*.h*\",\n \"include/TH/generic/*.h*\",\n \"include/THC/*.cuh\",\n \"include/THC/*.h*\",\n \"include/THC/generic/*.h\",\n \"include/THH/*.cuh\",\n \"include/THH/*.h*\",\n \"include/THH/generic/*.h\",\n \"include/sleef.h\",\n \"_inductor/codegen/*.h\",\n \"_inductor/codegen/aoti_runtime/*.cpp\",\n \"_export/serde/*.yaml\",\n \"share/cmake/ATen/*.cmake\",\n \"share/cmake/Caffe2/*.cmake\",\n \"share/cmake/Caffe2/public/*.cmake\",\n \"share/cmake/Caffe2/Modules_CUDA_fix/*.cmake\",\n \"share/cmake/Caffe2/Modules_CUDA_fix/upstream/*.cmake\",\n \"share/cmake/Caffe2/Modules_CUDA_fix/upstream/FindCUDA/*.cmake\",\n \"share/cmake/Gloo/*.cmake\",\n \"share/cmake/Tensorpipe/*.cmake\",\n \"share/cmake/Torch/*.cmake\",\n \"utils/benchmark/utils/*.cpp\",\n \"utils/benchmark/utils/valgrind_wrapper/*.cpp\",\n \"utils/benchmark/utils/valgrind_wrapper/*.h\",\n \"utils/model_dump/skeleton.html\",\n \"utils/model_dump/code.js\",\n \"utils/model_dump/*.mjs\",\n ]\n\n if not BUILD_LIBTORCH_WHL:\n torch_package_data.extend(\n [\n \"lib/libtorch_python.so\",\n \"lib/libtorch_python.dylib\",\n \"lib/libtorch_python.dll\",\n ]\n )\n if not BUILD_PYTHON_ONLY:\n torch_package_data.extend(\n [\n \"lib/*.so*\",\n \"lib/*.dylib*\",\n \"lib/*.dll\",\n \"lib/*.lib\",\n ]\n )\n if get_cmake_cache_vars()[\"BUILD_CAFFE2\"]:\n torch_package_data.extend(\n [\n \"include/caffe2/**/*.h\",\n \"include/caffe2/utils/*.h\",\n \"include/caffe2/utils/**/*.h\",\n ]\n )\n if get_cmake_cache_vars()[\"USE_TENSORPIPE\"]:\n torch_package_data.extend(\n [\n \"include/tensorpipe/*.h\",\n \"include/tensorpipe/channel/*.h\",\n \"include/tensorpipe/channel/basic/*.h\",\n \"include/tensorpipe/channel/cma/*.h\",\n \"include/tensorpipe/channel/mpt/*.h\",\n \"include/tensorpipe/channel/xth/*.h\",\n \"include/tensorpipe/common/*.h\",\n \"include/tensorpipe/core/*.h\",\n \"include/tensorpipe/transport/*.h\",\n \"include/tensorpipe/transport/ibv/*.h\",\n \"include/tensorpipe/transport/shm/*.h\",\n \"include/tensorpipe/transport/uv/*.h\",\n ]\n )\n if get_cmake_cache_vars()[\"USE_KINETO\"]:\n torch_package_data.extend(\n [\n \"include/kineto/*.h\",\n ]\n )\n torchgen_package_data = [\n # Recursive glob doesn't work in setup.py,\n # https://github.com/pypa/setuptools/issues/1806\n # To make this robust we should replace it with some code that\n # returns a list of everything under packaged/\n \"packaged/ATen/*\",\n \"packaged/ATen/native/*\",\n \"packaged/ATen/templates/*\",\n \"packaged/autograd/*\",\n \"packaged/autograd/templates/*\",\n ]\n package_data = {\n \"torch\": torch_package_data,\n }\n\n if not BUILD_LIBTORCH_WHL:\n package_data[\"torchgen\"] = torchgen_package_data\n package_data[\"caffe2\"] = [\n \"python/serialized_test/data/operator_test/*.zip\",\n ]\n else:\n # no extensions in BUILD_LIBTORCH_WHL mode\n extensions = []\n\n setup(\n name=package_name,\n version=version,\n description=(\n \"Tensors and Dynamic neural networks in \"\n \"Python with strong GPU acceleration\"\n ),\n long_description=long_description,\n long_description_content_type=\"text/markdown\",\n ext_modules=extensions,\n cmdclass=cmdclass,\n packages=packages,\n entry_points=entry_points,\n install_requires=install_requires,\n extras_require=extras_require,\n package_data=package_data,\n url=\"https://pytorch.org/\",\n download_url=\"https://github.com/pytorch/pytorch/tags\",\n author=\"PyTorch Team\",\n author_email=\"packages@pytorch.org\",\n python_requires=f\">={python_min_version_str}\",\n # PyPI package information.\n classifiers=[\n \"Development Status :: 5 - Production/Stable\",\n \"Intended Audience :: Developers\",\n \"Intended Audience :: Education\",\n \"Intended Audience :: Science/Research\",\n \"License :: OSI Approved :: BSD License\",\n \"Topic :: Scientific/Engineering\",\n \"Topic :: Scientific/Engineering :: Mathematics\",\n \"Topic :: Scientific/Engineering :: Artificial Intelligence\",\n \"Topic :: Software Development\",\n \"Topic :: Software Development :: Libraries\",\n \"Topic :: Software Development :: Libraries :: Python Modules\",\n \"Programming Language :: C++\",\n \"Programming Language :: Python :: 3\",\n ]\n + [\n f\"Programming Language :: Python :: 3.{i}\"\n for i in range(python_min_version[1], version_range_max)\n ],\n license=\"BSD-3-Clause\",\n keywords=\"pytorch, machine learning\",\n )\n if EMIT_BUILD_WARNING:\n print_box(build_update_message)\n\n\nif __name__ == \"__main__\":\n main()\n" | |
| } | |
| ] | |
| }, | |
| { | |
| "url": "https://github.com/netdata/netdata", | |
| "files": [] | |
| }, | |
| { | |
| "url": "https://github.com/microsoft/ML-For-Beginners", | |
| "files": [ | |
| { | |
| "name": "docsifytopdf.js", | |
| "content": "module.exports = {\n\tcontents: ['docs/_sidebar.md'], // array of \"table of contents\" files path\n\tpathToPublic: 'pdf/readme.pdf', // path where pdf will stored\n\tpdfOptions: {\n\t\tmargin: { top: '100px', bottom: '100px' }\n\t}, // reference: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions\n\tremoveTemp: true, // remove generated .md and .html or not\n\temulateMedia: 'print', // mediaType, emulating by puppeteer for rendering pdf, 'print' by default (reference: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageemulatemediamediatype)\n};\n" | |
| } | |
| ] | |
| } | |
| ] |