Skip to content

Commit

Permalink
Merge pull request #1834 from opentensor/feature/1833/cache-get-decod…
Browse files Browse the repository at this point in the history
…er-class

Cache get_decoder_class
  • Loading branch information
thewhaleking committed May 2, 2024
2 parents 752c1ad + 05b2794 commit 3b47287
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions bittensor/subtensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
import functools

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
Expand Down Expand Up @@ -92,6 +93,21 @@
T = TypeVar("T")


#######
# Monkey patch in caching the get_decoder_class method
#######
if hasattr(RuntimeConfiguration, "get_decoder_class"):
original_get_decoder_class = RuntimeConfiguration.get_decoder_class

@functools.lru_cache(maxsize=None)
def cached_get_decoder_class(self, type_string):
return original_get_decoder_class(self, type_string)

RuntimeConfiguration.get_decoder_class = cached_get_decoder_class

#######


class ParamWithTypes(TypedDict):
name: str # Name of the parameter.
type: str # ScaleType string of the parameter.
Expand Down
2 changes: 1 addition & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pytest
retry
requests
rich
scalecodec==1.2.7
scalecodec==1.2.7 # scalecodec should not be changed unless first verifying compatibility with the subtensor's monkeypatching of scalecodec.RuntimeConfiguration.get_decoder_class
shtab==1.6.5
substrate-interface==1.7.5
termcolor
Expand Down
2 changes: 1 addition & 1 deletion scripts/environments/apple_m1_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ dependencies:
- retry==0.9.2
- rich==12.5.1
- rsa==4.9
- scalecodec==1.2.7
- scalecodec==1.2.7 # scalecodec should not be changed unless first verifying compatibility with the subtensor's monkeypatching of scalecodec.RuntimeConfiguration.get_decoder_class
- scikit-learn==1.2.2
- scipy==1.10.1
- sentencepiece==0.1.99
Expand Down

0 comments on commit 3b47287

Please sign in to comment.