Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache get_decoder_class #1834

Merged
merged 8 commits into from
May 2, 2024
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