Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Conversation

@donatasm
Copy link
Contributor

@donatasm donatasm commented Aug 22, 2022

Lazy load ML dependencies (torch, keras, xgboost) in the __init__ to lower the import times when the libs are not used. Also, pandas and pyarrow imports were moved from the module tops into the methods.

Before the change (with torch installed):

python -c "import layer"  3.52s user 0.77s system 128% cpu 3.325 total

After the change:

python -c "import layer"  1.95s user 0.44s system 214% cpu 1.114 total

IMHO there're still to much being done in the __init__ and could be improved further, but that's a good start. Some data on what's going on (using importtime_output_wrapper to format the output):

python -m importtime_output_wrapper -m layer --depth 8 --width 600 --time cumulative --format waterfall 1> imports.log
module name                                                              import time (us)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
zipimport                                                                (102)
_frozen_importlib_external                                               (592)
encodings                                                                (2168)
.codecs                                                                  (563)
.._codecs                                                                (60)
.encodings.aliases                                                       (510)
encodings.utf_8                                                          (216)
_signal                                                                  (89)
encodings.latin_1                                                        (314)
io                                                                       (599)
.abc                                                                     (318)
.._abc                                                                   (43)
_bootlocale                                                              (225)
._locale                                                                 (72)
site                                                                     ====(14172)
.os                                                                      (2306)
..stat                                                                   (331)
..._stat                                                                 (134)
.._collections_abc                                                       (982)
..posixpath                                                              (413)
...genericpath                                                           (177)
._sitebuiltins                                                           (195)
._distutils_hack                                                         (1346)
.types                                                                   (284)
.importlib.util                                                          ==(6252)
..importlib                                                              (480)
...warnings                                                              (290)
..importlib.abc                                                          (646)
...importlib.machinery                                                   (173)
..contextlib                                                             =(4784)
...collections                                                           =(3451)
....operator                                                             (397)
....._operator                                                           (74)
....keyword                                                              (159)
....heapq                                                                (1049)
....._heapq                                                              (846)
....itertools                                                            (125)
....reprlib                                                              (259)
...._collections                                                         (150)
...functools                                                             (644)
...._functools                                                           (60)
.sitecustomize                                                           (86)
.usercustomize                                                           (71)
layer                                                                    ======================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================(1476172)
.typing                                                                  =(4769)
..collections.abc                                                        (199)
..re                                                                     =(2988)
...enum                                                                  (875)
...sre_compile                                                           (1268)
...._sre                                                                 (81)
....sre_parse                                                            (858)
.....sre_constants                                                       (431)
...copyreg                                                               (217)
.lazy_loader                                                             ==(8029)
..ast                                                                    (1769)
..._ast                                                                  (1309)
..inspect                                                                ==(5791)
...dis                                                                   (2285)
....opcode                                                               (1586)
....._opcode                                                             (1056)
...linecache                                                             (1627)
....tokenize                                                             (1414)
.....token                                                               (312)
.layer.context                                                           ========================================================================================================================================================================================================================================================================================================================================================================================================================(1162893)
..layer.contracts.asset                                                  ======================================================================================(246254)
...layer.contracts                                                       (568)
...uuid                                                                  (1901)
...._uuid                                                                (1168)
...dataclasses                                                           (2395)
....copy                                                                 (1448)
.....weakref                                                             (707)
......_weakrefset                                                        (265)
.....org.python.core                                                     (128)
......org.python                                                         (114)
.......org                                                               (101)
...pathlib                                                               =(4659)
....fnmatch                                                              (198)
....ntpath                                                               (985)
.....nt                                                                  (103)
.....nt                                                                  (88)
.....nt                                                                  (90)
....errno                                                                (99)
....urllib.parse                                                         (2369)
.....urllib                                                              (635)
...yarl                                                                  =========(25576)
....yarl._url                                                            ========(25126)
.....ipaddress                                                           (1595)
.....multidict                                                           ====(13086)
......multidict._abc                                                     (858)
......multidict._compat                                                  ====(11638)
.......platform                                                          ===(9464)
.......multidict._multidict                                              (1847)
.....idna                                                                ==(5713)
......idna.package_data                                                  (507)
......idna.core                                                          =(4751)
.......idna.idnadata                                                     (284)
.......bisect                                                            (1398)
.......unicodedata                                                       (1438)
.......idna.intranges                                                    (229)
.....yarl._quoting                                                       =(3337)
......yarl._quoting_c                                                    =(2935)
.......string                                                            (1123)
...layer.cache.cache                                                     =========================================================================(208260)
....layer.cache                                                          (955)
....layer.config                                                         ========================================================================(206842)
.....layer.config.config                                                 ================================================================(182553)
......json                                                               (2423)
.......json.decoder                                                      (1655)
.......json.encoder                                                      (533)
......datetime                                                           =(2961)
......._datetime                                                         (1770)
......jwt                                                                ==============================(86410)
.......jwt.api_jwk                                                       ==============(39923)
.......jwt.api_jws                                                       (387)
.......jwt.api_jwt                                                       (2052)
.......jwt.jwks_client                                                   ===============(43345)
......layer.exceptions.exceptions                                        ==============================(85432)
.......layer.exceptions                                                  ==============================(85408)
......layer.utils.session                                                (875)
.......layer.utils                                                       (540)
.....layer.config.config_client                                          (401)
.....layer.config.config_manager                                         ========(23522)
......layer.auth                                                         =(3417)
.......secrets                                                           (490)
.......webbrowser                                                        (1306)
......layer.config.guest_login_client                                    ======(19652)
.......layerapi.api.service.account.user_api_pb2                         ==(6036)
.......layerapi.api.service.account.user_api_pb2_grpc                    (429)
.......layer.utils.grpc.channel                                          ====(12757)
...layer.contracts.project_full_name                                     (617)
..layer.contracts.datasets                                               ====================================================================================================================================================================================================================================================================================================(832443)
...layer.contracts.logged_data                                           =================================================================================================================================================================================================================================================================================================(824272)
....numpy                                                                =============================================================(176037)
.....numpy._globals                                                      (593)
.....numpy.__config__                                                    (301)
.....numpy._version                                                      (455)
.....numpy._distributor_init                                             (349)
.....numpy.core                                                          ===============================(89606)
......numpy.version                                                      (274)
......numpy.core.multiarray                                              ==========(30455)
.......numpy.core.overrides                                              ==========(28406)
......numpy.core.umath                                                   (466)
......numpy.core.numerictypes                                            (2042)
.......numpy.core._string_helpers                                        (405)
.......numpy.core._type_aliases                                          (991)
......numpy.core.numeric                                                 ===(10263)
.......numpy.core.shape_base                                             ==(5777)
.......numpy.core._ufunc_config                                          (569)
.......numpy.core.arrayprint                                             (1125)
.......numpy.core._asarray                                               (491)
......numpy.core.defchararray                                            =(3340)
......numpy.core.records                                                 (654)
......numpy.core.memmap                                                  (397)
......numpy.core.function_base                                           (522)
......numpy.core.machar                                                  (333)
......numpy.core.getlimits                                               (521)
......numpy.core.einsumfunc                                              (677)
......numpy.core._add_newdocs                                            =(4690)
.......numpy.core._multiarray_tests                                      =(2938)
......numpy.core._add_newdocs_scalars                                    ==========(30834)
......numpy.core._dtype_ctypes                                           (614)
......numpy.core._internal                                               (1726)
......numpy._pytesttester                                                (525)
.....numpy.lib                                                           ==========(30491)
......numpy.lib.mixins                                                   (455)
......numpy.lib.scimath                                                  =(4535)
.......numpy.lib.type_check                                              (1927)
......numpy.lib.index_tricks                                             =====(14851)
.......numpy.matrixlib                                                   ===(10097)
.......numpy.lib.function_base                                           =(3745)
......numpy.lib.nanfunctions                                             (1220)
......numpy.lib.shape_base                                               (1246)
......numpy.lib.polynomial                                               (1228)
......numpy.lib.utils                                                    (1004)
......numpy.lib.arraysetops                                              (868)
......numpy.lib.npyio                                                    (2795)
.......numpy.lib.format                                                  (480)
.......numpy.lib._datasource                                             (585)
.......numpy.lib._iotools                                                (564)
......numpy.lib.arrayterator                                             (224)
......numpy.lib.arraypad                                                 (460)
......numpy.lib._version                                                 (454)
.....numpy.fft                                                           =(3582)
......numpy.fft._pocketfft                                               (2798)
.......numpy.fft._pocketfft_internal                                     (1423)
......numpy.fft.helper                                                   (324)
.....numpy.polynomial                                                    =(5366)
......numpy.polynomial.polynomial                                        (2593)
.......numpy.polynomial.polyutils                                        (451)
.......numpy.polynomial._polybase                                        (721)
......numpy.polynomial.chebyshev                                         (520)
......numpy.polynomial.legendre                                          (499)
......numpy.polynomial.hermite                                           (579)
......numpy.polynomial.hermite_e                                         (493)
......numpy.polynomial.laguerre                                          (440)
.....numpy.random                                                        ========(23824)
......numpy.random._pickle                                               ========(23315)
.......numpy.random.mtrand                                               =====(14952)
.......numpy.random._philox                                              (1246)
.......numpy.random._pcg64                                               (1373)
.......numpy.random._sfc64                                               (1203)
.......numpy.random._generator                                           =(4033)
.....numpy.ctypeslib                                                     (715)
.....numpy.ma                                                            ==(6276)
......numpy.ma.core                                                      =(4108)
......numpy.ma.extras                                                    (1649)
....pandas                                                               =============================================================================================================================================================================================================(584161)
.....pytz                                                                =(4111)
......pytz.exceptions                                                    (977)
......pytz.lazy                                                          (477)
......pytz.tzinfo                                                        (518)
......pytz.tzfile                                                        (345)
.....dateutil                                                            (1126)
......dateutil._version                                                  (649)
.....pandas.compat                                                       ==========================================================================================================(302915)
......pandas._typing                                                     =(3914)
.......mmap                                                              (1421)
......pandas.compat.numpy                                                ====================================(104381)
.......pandas.util.version                                               ====================================(103517)
......pandas.compat.pyarrow                                              ====================================================================(193796)
.......pyarrow                                                           ===================================================================(193406)
.....pandas.core.config_init                                             (1108)
.....pandas.core.api                                                     ================================================================================(228691)
......pandas.core.dtypes.missing                                         (404)
......pandas.core.algorithms                                             =(4789)
.......pandas.core.dtypes.cast                                           (1258)
.......pandas.core.array_algos.take                                      (2038)
.......pandas.core.indexers                                              (475)
......pandas.core.arrays                                                 ==============================================(132120)
.......pandas.core.arrays.base                                           ===(10316)
.......pandas.core.arrays.boolean                                        ====(12403)
.......pandas.core.arrays.categorical                                    ====(13606)
.......pandas.core.arrays.datetimes                                      ==(6114)
.......pandas.core.arrays.floating                                       (439)
.......pandas.core.arrays.interval                                       ======(18270)
.......pandas.core.arrays.numpy_                                         (316)
.......pandas.core.arrays.period                                         (630)
.......pandas.core.arrays.string_                                        (518)
.......pandas.core.arrays.string_arrow                                   ========================(68421)
.......pandas.core.arrays.timedeltas                                     (612)
......pandas.core.flags                                                  (366)
......pandas.core.groupby                                                ===============================(90650)
.......pandas.core.groupby.generic                                       ===============================(90350)
.....pandas.tseries.api                                                  (301)
.....pandas.core.computation.api                                         =(4463)
......pandas.core.computation.eval                                       =(4219)
.......pandas.core.computation.engines                                   =(3904)
.....pandas.core.reshape.api                                             =(3791)
......pandas.core.reshape.merge                                          (967)
......pandas.core.reshape.pivot                                          (1134)
......pandas.core.reshape.reshape                                        (1135)
......pandas.core.reshape.tile                                           (259)
.....pandas.api                                                          (1401)
......pandas.api.extensions                                              (596)
......pandas.api.indexers                                                (219)
......pandas.api.types                                                   (314)
.......pandas.core.dtypes.api                                            (163)
.....pandas.util._print_versions                                         (289)
.....pandas.io.api                                                       =========(27879)
......pandas.io.clipboards                                               (252)
......pandas.io.excel                                                    =====(15020)
.......pandas.io.excel._base                                             ===(10973)
.......pandas.io.excel._odswriter                                        =(3188)
.......pandas.io.excel._xlsxwriter                                       (318)
.......pandas.io.excel._xlwt                                             (200)
......pandas.io.feather_format                                           (352)
......pandas.io.gbq                                                      (403)
......pandas.io.html                                                     (769)
......pandas.io.json                                                     (2447)
.......pandas.io.json._json                                              (2286)
......pandas.io.orc                                                      (152)
......pandas.io.parquet                                                  (499)
......pandas.io.pickle                                                   (938)
.......pandas.compat.pickle_compat                                       (383)
......pandas.io.pytables                                                 (2603)
.......pandas.core.computation.pytables                                  (611)
......pandas.io.sas                                                      (655)
.......pandas.io.sas.sasreader                                           (375)
......pandas.io.spss                                                     (154)
......pandas.io.sql                                                      (682)
......pandas.io.stata                                                    (1854)
......pandas.io.xml                                                      (884)
.....pandas.util._tester                                                 (273)
.....pandas.testing                                                      ==(6678)
......pandas._testing                                                    ==(6435)
.......pandas._testing._io                                               (1264)
.......pandas._testing._warnings                                         (168)
.......pandas._testing.asserters                                         =(3760)
.......pandas._testing.compat                                            (177)
.....pandas._version                                                     (164)
....requests                                                             =====================(60944)
.....urllib3                                                             ========(24192)
......urllib3.exceptions                                                 =(3295)
.......urllib3.packages.six.moves.http_client                            (1862)
......urllib3._version                                                   (273)
......urllib3.connectionpool                                             ======(19432)
.......urllib3.connection                                                =====(16363)
.......urllib3.request                                                   (1568)
.......urllib3.response                                                  (762)
.......urllib3.util.queue                                                (173)
......urllib3.poolmanager                                                (600)
.....requests.exceptions                                                 ======(18272)
......requests.compat                                                    ======(17283)
.......chardet                                                           ===(10935)
.......simplejson                                                        (126)
.......http.cookiejar                                                    =(4047)
.......http.cookies                                                      (1890)
.....charset_normalizer                                                  ==(8285)
......charset_normalizer.api                                             ==(7014)
.......charset_normalizer.cd                                             ==(6009)
......charset_normalizer.legacy                                          (430)
......charset_normalizer.version                                         (242)
.....requests.packages                                                   (1620)
.....requests.utils                                                      =(4363)
......requests.certs                                                     (1508)
.......certifi                                                           (1272)
......requests.__version__                                               (253)
......requests._internal_utils                                           (597)
......requests.cookies                                                   (358)
......requests.structures                                                (896)
.....requests.api                                                        =(3653)
......requests.sessions                                                  =(3479)
.......requests.adapters                                                 =(3153)
....layer.logged_data.utils                                              (753)
.....layer.logged_data                                                   (384)
...layer.logged_data.log_data_runner                                     ==(5870)
....layerapi.api.value.logged_data_type_pb2                              (1861)
.....layerapi.api.value                                                  (418)
....layer.clients.logged_data_service                                    =(3256)
.....layer.clients                                                       (258)
.....layerapi.api.entity.logged_model_metric_pb2                         (415)
.....layerapi.api.service.logged_data.logged_data_api_pb2                (1611)
......layerapi.api.service.logged_data                                   (363)
......layerapi.api.entity.logged_data_pb2                                (377)
.....layerapi.api.service.logged_data.logged_data_api_pb2_grpc           (346)
..layer.tracker.ui_progress_tracker                                      =============================(82958)
...layer.tracker                                                         (230)
...rich.progress                                                         ======================(63316)
....rich                                                                 (1597)
.....rich._extension                                                     (936)
....rich.filesize                                                        (410)
....rich.console                                                         ===================(55390)
.....getpass                                                             (2067)
......termios                                                            (1623)
.....html                                                                (2000)
......html.entities                                                      (1274)
.....rich.errors                                                         (398)
.....rich.themes                                                         ===(9811)
......rich.default_styles                                                ==(6332)
.......rich.style                                                        =(5354)
......rich.theme                                                         =(2969)
.......configparser                                                      (2449)
.....rich._emoji_replace                                                 (2627)
......rich._emoji_codes                                                  (2037)
.....rich._export_format                                                 (293)
.....rich._log_render                                                    ===(9114)
......rich.text                                                          ===(8703)
.......rich.emoji                                                        =(3800)
.......rich._loop                                                        (383)
.......rich._pick                                                        (153)
.......rich._wrap                                                        (374)
.......rich.align                                                        (1592)
.......rich.containers                                                   (564)
.......rich.control                                                      (500)
.....rich.highlighter                                                    (1284)
.....rich.markup                                                         (1136)
.....rich.pager                                                          (343)
.....rich.pretty                                                         =====(16234)
......array                                                              (2077)
......attr                                                               ====(11705)
.......attr.converters                                                   =(5598)
.......attr.filters                                                      (217)
.......attr.validators                                                   =(3465)
.......attr._cmp                                                         (388)
.......attr._funcs                                                       (378)
.......attr._version_info                                                (697)
.......attr._next_gen                                                    (343)
......rich.abc                                                           (204)
.....rich.region                                                         (419)
.....rich.scope                                                          =(5467)
......rich.panel                                                         (1103)
.......rich.box                                                          (485)
.......rich.padding                                                      (293)
......rich.table                                                         =(4001)
.......rich._ratio                                                       (1866)
.....rich.screen                                                         (251)
.....rich.styled                                                         (312)
....rich.live                                                            (2040)
.....rich.file_proxy                                                     (1043)
......rich.ansi                                                          (685)
.....rich.live_render                                                    (352)
....rich.progress_bar                                                    (413)
....rich.spinner                                                         (650)
.....rich._spinners                                                      (382)
...layer.contracts.tracker                                               (1719)
...layer.tracker.output                                                  =====(16433)
....layer.tracker.asset_column                                           =====(16089)
.....humanize                                                            =====(15498)
......humanize.filesize                                                  (788)
......humanize.i18n                                                      (1421)
.......gettext                                                           (1145)
......humanize.number                                                    (268)
......humanize.time                                                      (398)
......importlib.metadata                                                 (49)
......importlib_metadata                                                 =(4853)
.......zipp                                                              (549)
.......importlib_metadata._adapters                                      (1146)
.......importlib_metadata._meta                                          (756)
.......importlib_metadata._collections                                   (437)
.......importlib_metadata._itertools                                     (235)
...layer.tracker.progress_tracker                                        (533)
..layer.training.base_train                                              (542)
...layer.training                                                        (180)
.layer.contracts.models                                                  ===================(54172)
..layerapi.api.value.aws_credentials_pb2                                 (359)
..layerapi.api.value.s3_path_pb2                                         (423)
..layer.flavors.base                                                     ==================(52176)
...layer.flavors                                                         ==================(52157)
....layer.flavors.base                                                   (1134)
.....layer.types                                                         (134)
....layer.flavors.catboost                                               (644)
.....layerapi.api.value.model_flavor_pb2                                 (301)
....layer.flavors.custom                                                 (344)
....layer.flavors.huggingface                                            (189)
....layer.flavors.keras                                                  (185)
....layer.flavors.lightgbm                                               =================(48533)
.....scipy.sparse                                                        =================(48325)
......scipy                                                              ===(10764)
.......scipy._lib.deprecation                                            (1926)
.......scipy.__config__                                                  (216)
.......scipy.version                                                     (363)
.......scipy._distributor_init                                           (343)
.......scipy._lib._pep440                                                (704)
.......scipy._lib._ccallback                                             =(2911)
......scipy.sparse.base                                                  (2035)
.......scipy.sparse.sputils                                              (1182)
......scipy.sparse.csr                                                   ===(9723)
.......scipy.sparse._sparsetools                                         ==(6841)
.......scipy.sparse.compressed                                           (2314)
......scipy.sparse.csc                                                   (534)
......scipy.sparse.lil                                                   =(4306)
.......scipy.sparse._csparsetools                                        =(3802)
......scipy.sparse.dok                                                   (591)
......scipy.sparse.coo                                                   (430)
......scipy.sparse.bsr                                                   (557)
......scipy.sparse.construct                                             (583)
......scipy.sparse.extract                                               (319)
......scipy.sparse._matrix_io                                            (298)
......scipy.sparse.csgraph                                               ======(17035)
.......scipy.sparse.csgraph._laplacian                                   (353)
.......scipy.sparse.csgraph._shortest_path                               =(5083)
.......scipy.sparse.csgraph._traversal                                   (1768)
.......scipy.sparse.csgraph._min_spanning_tree                           (1933)
.......scipy.sparse.csgraph._flow                                        (2585)
.......scipy.sparse.csgraph._matching                                    (2255)
.......scipy.sparse.csgraph._reordering                                  (2420)
....layer.flavors.pytorch                                                (242)
....layer.flavors.sklearn                                                (194)
....layer.flavors.tensorflow                                             (189)
....layer.flavors.xgboost                                                (182)
.layer.contracts.projects                                                =(4921)
..layerapi.api.entity.operations_pb2                                     (1314)
...layerapi.api.entity.task_pb2                                          (434)
...layerapi.api.value.language_version_pb2                               (363)
..layer.contracts.accounts                                               (2189)
.layer.contracts.runs                                                    (1684)
..layerapi.api.entity.run_pb2                                            (478)
.layer.decorators                                                        =========================================================(163355)
..layer.decorators.conda_decorator                                       ========================================================(161387)
...layer.contracts.conda                                                 =======(22389)
....yaml                                                                 =======(21594)
.....yaml.error                                                          (469)
.....yaml.tokens                                                         (598)
.....yaml.events                                                         (415)
.....yaml.nodes                                                          (291)
.....yaml.loader                                                         =====(14566)
......yaml.reader                                                        ===(9142)
......yaml.scanner                                                       (551)
......yaml.parser                                                        (335)
......yaml.composer                                                      (206)
......yaml.constructor                                                   (1298)
......yaml.resolver                                                      (2702)
.....yaml.dumper                                                         (1136)
......yaml.emitter                                                       (370)
......yaml.serializer                                                    (205)
......yaml.representer                                                   (304)
.....yaml.cyaml                                                          =(3325)
......yaml._yaml                                                         =(2955)
.......yaml.yaml                                                         (61)
...layer.decorators.layer_wrapper                                        ================================================(138630)
....layer.contracts.definitions                                          ==(6294)
.....layer.contracts.fabrics                                             (474)
.....layer.executables.packager                                          =(5354)
......layer.executables                                                  (770)
......glob                                                               (538)
......zipapp                                                             (441)
......layer.cloudpickle                                                  (2355)
.......layer.cloudpickle.cloudpickle                                     (1086)
.......layer.cloudpickle.cloudpickle_fast                                (562)
....layer.projects.utils                                                 ==============================================(131239)
.....layer.projects                                                      (314)
.....layer.clients.layer                                                 =============================================(129079)
......layer.clients.account_service                                      ==(7502)
.......layerapi.api.entity.account_view_pb2                              (319)
.......layerapi.api.service.account.account_api_pb2                      ==(6341)
.......layerapi.api.service.account.account_api_pb2_grpc                 (397)
......layer.clients.data_catalog                                         =============================(84458)
.......layerapi.api.entity.dataset_build_pb2                             (1516)
.......layerapi.api.entity.dataset_pb2                                   (667)
.......layerapi.api.entity.dataset_version_pb2                           (194)
.......layerapi.api.service.datacatalog.data_catalog_api_pb2             =(3115)
.......layerapi.api.service.datacatalog.data_catalog_api_pb2_grpc        (484)
.......layerapi.api.service.dataset.dataset_api_pb2                      (1066)
.......layer.utils.file_utils                                            (1381)
.......layer.utils.s3                                                    (287)
.......layer.clients.dataset_service                                     ==========================(75044)
......layer.clients.executor_service                                     (2033)
.......layerapi.api.service.executor.executor_api_pb2                    (1401)
.......layerapi.api.service.executor.executor_api_pb2_grpc               (244)
......layer.clients.flow_manager                                         =(5085)
.......layerapi.api.entity.history_event_pb2                             (292)
.......layerapi.api.entity.run_metadata_entry_pb2                        (282)
.......layerapi.api.entity.run_metadata_pb2                              (293)
.......layerapi.api.service.flowmanager.flow_manager_api_pb2             =(3415)
.......layerapi.api.service.flowmanager.flow_manager_api_pb2_grpc        (406)
......layer.clients.model_catalog                                        ========(23919)
.......layerapi.api.entity.model_train_pb2                               (486)
.......layerapi.api.entity.model_version_pb2                             (269)
.......layerapi.api.entity.source_code_environment_pb2                   (827)
.......layerapi.api.service.modelcatalog.model_catalog_api_pb2           =======(20457)
.......layerapi.api.service.modelcatalog.model_catalog_api_pb2_grpc      (682)
.......layer.flavors.utils                                               (573)
......layer.clients.model_training_service                               (2188)
.......polling                                                           (581)
.......layerapi.api.service.modeltraining.model_training_api_pb2         (896)
.......layerapi.api.service.modeltraining.model_training_api_pb2_grpc    (254)
......layer.clients.project_service                                      (2042)
.......layerapi.api.entity.project_pb2                                   (330)
.......layerapi.api.entity.project_view_pb2                              (200)
.......layerapi.api.service.flowmanager.project_api_pb2                  (825)
.......layerapi.api.service.flowmanager.project_api_pb2_grpc             (370)
......layer.clients.user_logs_service                                    (1443)
.......layerapi.api.entity.user_log_line_pb2                             (334)
.......layerapi.api.service.user_logs.user_logs_api_pb2                  (648)
.......layerapi.api.service.user_logs.user_logs_api_pb2_grpc             (209)
.....layer.global_context                                                (1135)
....layer.settings                                                       (525)
..layer.decorators.dataset_decorator                                     (383)
..layer.decorators.fabric_decorator                                      (170)
..layer.decorators.model_decorator                                       (201)
..layer.decorators.pip_requirements_decorator                            (379)
..layer.decorators.resources_decorator                                   (369)
.layer.decorators.assertions                                             (432)
.layer.main.asset                                                        =(3052)
..layer.main                                                             (589)
..layer.cache.utils                                                      (270)
..layer.tracker.utils                                                    (771)
...layer.tracker.non_ui_progress_tracker                                 (423)
..layer.utils.async_utils                                                (310)
..layer.main.utils                                                       (506)
...layer.main.version                                                    (245)
.layer.main.auth                                                         (425)
.layer.main.cache                                                        (385)
.layer.main.log                                                          (340)
.layer.main.run                                                          ========================(69107)
..layer.projects.init_project_runner                                     (393)
..layer.projects.project_runner                                          =======================(65615)
...aiohttp                                                               =====================(59806)
....aiohttp.hdrs                                                         (837)
....aiohttp.client                                                       ====================(57281)
.....aiohttp.http                                                        ============(34191)
......http.server                                                        =(4985)
.......socketserver                                                      (792)
......aiohttp.http_exceptions                                            (1260)
.......aiohttp.typedefs                                                  (717)
......aiohttp.http_parser                                                ======(18119)
.......aiohttp.base_protocol                                             (515)
.......aiohttp.helpers                                                   ===(9537)
.......aiohttp.http_writer                                               (2355)
.......aiohttp.streams                                                   (789)
.......brotli                                                            (128)
.......aiohttp._http_parser                                              =(3237)
......aiohttp.http_websocket                                             ===(9515)
.......aiohttp._websocket                                                (1235)
.....aiohttp.payload                                                     (1041)
.....aiohttp.client_exceptions                                           (1612)
.....aiohttp.client_reqrep                                               =(5263)
......aiohttp.multipart                                                  (1398)
......aiohttp.formdata                                                   (365)
......cchardet                                                           (121)
.....aiohttp.client_ws                                                   (562)
.....aiohttp.connector                                                   (2037)
......aiohttp.client_proto                                               (319)
......aiohttp.locks                                                      (290)
......aiohttp.resolver                                                   (461)
.......aiodns                                                            (112)
.....aiohttp.cookiejar                                                   (1272)
.....aiohttp.tracing                                                     ===(9100)
......aiohttp.signals                                                    (2020)
.......aiohttp.frozenlist                                                (1851)
....aiohttp.payload_streamer                                             (334)
....aiohttp.worker                                                       (766)
.....gunicorn.config                                                     (142)
......gunicorn                                                           (122)
...layer.executables.entrypoint.common                                   (1229)
....layer.executables.entrypoint                                         (738)
...layer.projects.execution_planner                                      (2496)
...layer.projects.progress_tracker_updater                               (521)
...layer.user_logs                                                       (1095)
..layer.projects.project_runner_old                                      (2636)
...layer.projects.execution_planner_old                                  (914)
...layer.projects.progress_tracker_updater_old                           (501)
...layer.resource_manager                                                (716)
....concurrent.futures.thread                                            (433)
.layer.pandas_extensions                                                 (1465)
WARNING: The waterfall diagram may not be displayed correctly if the set width is too small!

Also closes LAY-3341.

@linear
Copy link

linear bot commented Aug 22, 2022

LAY-3689 Lazilly load sdk dependencies that are not always needed

Description

part of https://github.com/layerai/roadmap/issues/19

Currently import layer is quite slow. We should reduce the number of large dependencies we load automatically and add a test to ensure we don't regress this if possible.

An inspiration can be taken in what we did last time we wanted to speed up the SDK - https://github.com/layerai/monorepo/pull/3146/files

Acceptance Criteria

  • [ ]

@donatasm donatasm force-pushed the donatas/lay-3689-lazilly-load-sdk-dependencies-that-are branch 9 times, most recently from 60bf650 to 2cbb8ba Compare August 23, 2022 19:43
requests = ">=2.23.0"
nvsmi = "^0.4.2"
psutil = ">=5.4.8" # Google Colab comes with 5.4.8 by default. If it gets upgraded an error message is shown saying the runtime needs to be restarted.
lazy-loader = {git = "https://github.com/layerai/lazy_loader.git", rev = "26aa52ab057afb0c3f85ffc64f220eae0e9a222c"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to fork, because lazy_loader only installs to python >= 3.8, but there were no blockers to lower the requirement.

@donatasm donatasm changed the title Lazy load dependencies Lazy load ML dependencies in the __init__ Aug 23, 2022
@donatasm donatasm force-pushed the donatas/lay-3689-lazilly-load-sdk-dependencies-that-are branch from 2cbb8ba to f6bf9b2 Compare August 23, 2022 20:38
@donatasm donatasm marked this pull request as ready for review August 23, 2022 20:43
Copy link
Contributor

@volkangurel volkangurel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the forked dependency, but looks like a good improvement so let's merge this in and we can iterate.

@donatasm donatasm merged commit 696730b into main Aug 24, 2022
@donatasm donatasm deleted the donatas/lay-3689-lazilly-load-sdk-dependencies-that-are branch August 24, 2022 05:19
donatasm added a commit that referenced this pull request Aug 24, 2022
@donatasm
Copy link
Contributor Author

Not sure about the forked dependency, but looks like a good improvement so let's merge this in and we can iterate.

It is a problem, indeed. Publishing to pip does not support direct dependencies. Proposed lowering minimum supported Python version to 3.7 in the upstream repo scientific-python/lazy-loader#14

donatasm pushed a commit that referenced this pull request Aug 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants