internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: microsoft/botbuilder-python

Issue:
valid_token_issuers incorrectly populated during SingleTenant validation
### [Github issues](https://github.com/Microsoft/botbuilder-python) should be used for bugs and feature requests. Use [Stack Overflow](https://stackoverflow.com/questions/tagged/botframework) for general "how-to" questions. 

## Version
4.15.0

## Describe the bug
Tenant specific token issuers (valid_token_issuers) are added as a nested element, instead of individual issuers.

## To Reproduce
Steps to reproduce the behavior:
Authenticating with app_type 'SingleTenant' will result in unauthorized requests.

## Expected behavior
Tenant specific token issues are treated as valid.




Discussion:

Resolving patch:
diff --git a/libraries/botframework-connector/botframework/connector/auth/skill_validation.py b/libraries/botframework-connector/botframework/connector/auth/skill_validation.py
--- a/libraries/botframework-connector/botframework/connector/auth/skill_validation.py
+++ b/libraries/botframework-connector/botframework/connector/auth/skill_validation.py
@@ -120,7 +120,7 @@ async def authenticate_channel_token(
         )
 
         if auth_configuration.valid_token_issuers:
-            token_validation_parameters.issuer.append(
+            token_validation_parameters.issuer.extend(
                 auth_configuration.valid_token_issuers
             )
 


Test patch:
Repository: microsoft/botbuilder-python

Issue:
CloudAdapterBase.update_activity using wrong activity id argument
```
        response = await connector_client.conversations.update_activity(
            activity.conversation.id, activity.reply_to_id, activity
        )
```

should be

```
        response = await connector_client.conversations.update_activity(
            activity.conversation.id, activity.id, activity
        )
```


Discussion:

Resolving patch:
diff --git a/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py b/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py
--- a/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py
+++ b/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py
@@ -120,7 +120,7 @@ async def update_activity(self, context: TurnContext, activity: Activity):
             raise Error("Unable to extract ConnectorClient from turn context.")
 
         response = await connector_client.conversations.update_activity(
-            activity.conversation.id, activity.reply_to_id, activity
+            activity.conversation.id, activity.id, activity
         )
 
         response_id = response.id if response and response.id else None


Test patch:
Repository: opentensor/bittensor

Issue:
Add readthedocs documentation
Repository is integrated with readthedocs , but it still requires actual documentation to be placed in it for it to be generated on readthedocs. The first thing we should start with is the NashTensor description, then a GRPC description, then the full SDK documentation can follow in another ticket.


Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644
--- /dev/null
+++ b/docs/conf.py
@@ -0,0 +1,50 @@
+# Configuration file for the Sphinx documentation builder.
+#
+# This file only contains a selection of the most common options. For a full
+# list see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+
+
+# -- Project information -----------------------------------------------------
+
+project = 'BitTensor'
+copyright = '2020, Jacob R. Steeves, Ala Shaabana'
+author = 'Jacob R. Steeves, Ala Shaabana'
+
+
+# -- General configuration ---------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = ['recommonmark']
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path.
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'alabaster'
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']


Test patch:
Repository: opentensor/bittensor

Issue:
Docker and python files take different cmd line arguments
Presently, docker run of Bittensor takes different flags as cmd line arguments than the typical Python native application.


This is because the dockerized version "assumes" all the flags for running it in python, when in reality it should be taking the same flags as the python cmd line arguments and passing them along until it runs the model in Python.




Discussion:

Resolving patch:
diff --git a/examples/mnist/main.py b/examples/mnist/main.py
--- a/examples/mnist/main.py
+++ b/examples/mnist/main.py
@@ -16,6 +16,10 @@
 import math
 import time
 import torch
+import torchvision
+from typing import List, Tuple, Dict, Optional
+import traceback
+
 import torch.nn as nn
 import torch.nn.functional as F
 import torch.optim as optim
@@ -338,6 +342,7 @@ def test( model: bittensor.Synapse ):
             epoch += 1
             
     except Exception as e:
+        traceback.print_exc()
         logger.error(e)
         metagraph.stop()
         axon.stop()


Test patch:
Repository: opentensor/bittensor

Issue:
Deploy BT on digitalocean
This PR enables us to deploy BT nodes on digitalocean for more large scale experimenting. 
Following container logs is now also an optional argument behind the command line argument `logging`. 

Node can be started with:
`./start_bittensor.sh -m <metagraph_port> -t <digital_ocean_token> --logging true`

Subsequent nodes can be started with
`./start_bittensor.sh --axon_port <bootstrap peer's axon port> --bootstrap <bootstrap peer's IP:port address> --token <digital_ocean_token>`


closes #48 


Discussion:

Resolving patch:
diff --git a/bittensor/dendrite.py b/bittensor/dendrite.py
--- a/bittensor/dendrite.py
+++ b/bittensor/dendrite.py
@@ -1,11 +1,13 @@
 from bittensor import bittensor_pb2_grpc as bittensor_grpc
 from bittensor import bittensor_pb2
 from bittensor.serializer import PyTorchSerializer
-import bittensor
 
 from loguru import logger
 from typing import List, Tuple, Dict, Optional
 
+from bittensor.exceptions.ResponseExceptions import EmptyTensorException
+
+import bittensor
 import os
 import grpc
 import PIL
@@ -86,7 +88,10 @@ def __init__(self, synapse: bittensor_pb2.Synapse, config: bittensor.Config):
         self.local_neuron_key = config.neuron_key       
         # Loop back if the synapse is local.
         if synapse.address == config.remote_ip:
-            self.endpoint = 'localhost:' + synapse.port
+            ip = "localhost:"
+            if config.remote_ip == "host.docker.internal":
+                ip = "host.docker.internal:"
+            self.endpoint = ip + synapse.port
         else:
             self.endpoint = synapse.address + ':' + synapse.port
         # TODO(const): should accept defaults. config = bittensor.config_or_defaults(config) 
@@ -148,10 +153,16 @@ def forward(ctx, caller: RemoteSynapse, dummy: torch.Tensor, inputs: torch.Tenso
         try:
             response = ctx.caller.stub.Forward(request)                
             # Deserialize outputs and return.
-            outputs = PyTorchSerializer.deserialize_tensor(response.tensors[0])
+            if len(response.tensors) > 0:
+                outputs = PyTorchSerializer.deserialize_tensor(response.tensors[0])
+            else:
+                raise EmptyTensorException
+            
         except grpc._channel._InactiveRpcError as ire:
             #logger.error("Could not forward() to peer: {}".format(ire))
             outputs = torch.zeros((inputs.size(0), bittensor.__network_dim__))
+        except EmptyTensorException as ete:
+            outputs = torch.zeros((inputs.size(0), bittensor.__network_dim__))
         
         return outputs
 
diff --git a/bittensor/exceptions/ResponseExceptions.py b/bittensor/exceptions/ResponseExceptions.py
new file mode 100644
--- /dev/null
+++ b/bittensor/exceptions/ResponseExceptions.py
@@ -0,0 +1,3 @@
+class EmptyTensorException (Exception):
+    """ Raised when tensor included in the response is unexpectedly empty """
+    pass
\ No newline at end of file


Test patch:
Repository: opentensor/bittensor

Issue:
Bit 590 backward fix
- Keep count of remote loss on server, saving model based on most 20 recent average loss.
- When doing tokenization remap, make sure the input size and output size is the same.
- Ensure encode_forward_causallmnext deterministic by set seed.
- When both local_train and remote_train are on: do local_train only when the server is free.
- Validator default to do backward train
Minor fixes
1) Removes the parser generation on the config with messes with --help when using a parser
2) Turns off console-rich local logging (which sucks)


Discussion:

Resolving patch:
diff --git a/bittensor/__init__.py b/bittensor/__init__.py
--- a/bittensor/__init__.py
+++ b/bittensor/__init__.py
@@ -23,7 +23,7 @@
 nest_asyncio.apply()
 
 # Bittensor code and protocol version.
-__version__ = '3.4.1'
+__version__ = '3.4.2'
 version_split = __version__.split(".")
 __version_as_int__ = (100 * int(version_split[0])) + (10 * int(version_split[1])) + (1 * int(version_split[2]))
 


Test patch:
Repository: opentensor/bittensor

Issue:
Miner error on netuid 1 - string indicies must be integers
When running a miner on netuid 1, we get this output with current text_prompting branch:

![image](https://user-images.githubusercontent.com/35969959/233508574-7502a388-a7cb-4748-b0f1-88bbcfbd3dfe.png)

It should cause an error for any miner, since what happens is that before the bittensor.BasePromptingMiner (in this case in neurons/text/prompting/miners/pythia/neuron.py) previously recieved the "messages" argument in the form of a list of dictionaries, but now gets it in the form of a list with strings.

To clarify,efore, we got something like this:

[{'role': 'system', 'content': '\nYou are designed to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics.\n'}, {'role': 'user', 'content': '\nAsk me a random question about anything. Make the question very domain specific. Do not include the answer in the question.\n'}]

Now we get something like this:

['{"role": "system", "content": "\\nYou are designed to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics.\\n"}', '{"role": "user", "content": "What is the function of the Golgi apparatus in a eukaryotic cell?"}']


While making a more permanent fix to this issue, I can confirm that this quickfix works:

Adding this to the start of the  forward() function in the miner, in this case in this case in neurons/text/prompting/miners/pythia/neuron.py:

```
            import json
            messages = [json.loads(item) for item in messages]
```

It takes all the strings in the messages variable and turns them into dictionaries.



Discussion:

Resolving patch:
diff --git a/bittensor/_synapse/text_prompting/synapse.py b/bittensor/_synapse/text_prompting/synapse.py
--- a/bittensor/_synapse/text_prompting/synapse.py
+++ b/bittensor/_synapse/text_prompting/synapse.py
@@ -21,6 +21,7 @@
 
 from typing import List, Dict, Union, Callable
 from abc import ABC, abstractmethod
+import json
 
 class SynapseForward( bittensor.SynapseCall ):
     name: str = "text_prompting_forward"
@@ -35,7 +36,7 @@ def __init__(
         ):
         super().__init__( synapse = synapse, request_proto = request_proto )
         self.messages = request_proto.messages
-        self.formatted_messages = [ message for message in self.messages ]
+        self.formatted_messages = [ json.loads(message) for message in self.messages ]
         self.forward_callback = forward_callback
 
     def apply( self ):


Test patch:
Repository: opentensor/bittensor

Issue:
Cache get_decoder_class
Currently, a large portion of time (29000+ calls for get_delegates) for RPC calls is taken up by decoding. Profiling this shows that the vast majority of this decoding time is actually caused by calls to the `scalecodec.base.RuntimeConfiguration.get_decoder_class` method. 

Because of the fairly limited number of decoder classes, we should be able to cache this with `functools.cache` to see large speed improvements.


Discussion:
Because the decoding is being done by a third-party library (scalecodec), we will have to monkey-patch in a `functools.cache` call like so:

```python

import functools
from scalecodec import base as scalecodec_base
import bittensor as bt

original_get_decoder_class = scalecodec_base.RuntimeConfiguration.get_decoder_class


@functools.cache
def patched_get_decoder_class(self, type_string):
    return original_get_decoder_class(self, type_string)


scalecodec_base.RuntimeConfiguration.get_decoder_class = patched_get_decoder_class

sub = bt.subtensor("finney")
sub.get_delegates()
```

With this, we can see a reduction of calls (for `get_delegates`) of the `get_decoder_class` method  from 94,542 to 332.  

In real-world performance, we see that the entire execution time for this script improves by ~48% with the patch implemented. Note that this only involves running five times each, so results may vary with times of day, ping, etc.:

| Original | Patched | Run |
| -------- | ------- | --- |
| 3.754099130630493| 2.3359689712524414| 0 |
| 4.5155346393585205| 2.0710458755493164| 1 |
| 4.193195104598999| 2.0840811729431152| 2 |
| 4.192205905914307| 2.0497679710388184| 3 |
| 3.9943289756774902| 2.2274067401885986| 4 |
| 4.129872751235962 | 2.153654146194458 | average |

I believe implementing this in the code base will drastically reduce overall decode time.



Resolving patch:
diff --git a/bittensor/subtensor.py b/bittensor/subtensor.py
--- a/bittensor/subtensor.py
+++ b/bittensor/subtensor.py
@@ -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
@@ -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.


Test patch:
Repository: opentensor/bittensor

Issue:
Typo and bad error message


![Image](https://github.com/opentensor/bittensor/assets/37844818/0decf37d-3710-4996-b473-cb3f591fea3c)

This is the error given from a `scalecodec.exceptions.RemainingScaleBytesNotEmptyException` in `subtensor.get_balance`, but I don't think this is necessarily the case. Regardless, the typo needs fixed.


Discussion:

Resolving patch:
diff --git a/bittensor/subtensor.py b/bittensor/subtensor.py
--- a/bittensor/subtensor.py
+++ b/bittensor/subtensor.py
@@ -4415,7 +4415,7 @@ def make_substrate_call_with_retry():
             result = make_substrate_call_with_retry()
         except scalecodec.exceptions.RemainingScaleBytesNotEmptyException:
             bittensor.logging.error(
-                "Your wallet it legacy formatted, you need to run btcli stake --ammount 0 to reformat it."
+                "Received a corrupted message. This likely points to an error with the network or subnet."
             )
             return Balance(1000)
         return Balance(result.value["data"]["free"])


Test patch:
diff --git a/tests/unit_tests/test_subtensor.py b/tests/unit_tests/test_subtensor.py
--- a/tests/unit_tests/test_subtensor.py
+++ b/tests/unit_tests/test_subtensor.py
@@ -177,7 +177,7 @@ def test_stake_multiple():
         # args, kwargs
         _, kwargs = mock_do_stake.call_args
 
-        assert kwargs["ammount"] == pytest.approx(
+        assert kwargs["amount"] == pytest.approx(
             mock_amount.rao, rel=1e9
         )  # delta of 1.0 TAO
Repository: opentensor/bittensor

Issue:
Remove nest_asyncio from bittensor to allow uvloop support
### Is your feature request related to a problem? Please describe.

Uvloop, which provides supperior speed, does not allow loop nesting.

It is also the case that uvloop is pulled in by popular packages, which [forces some subnets develop hacks to combat this](https://github.com/synapsec-ai/llm-defender-subnet/blob/6c37925c4f34a298607c97dfceebcc01fb74d562/scripts/run_neuron.sh#L140-L146).

And perhaps more importantly, https://github.com/erdewit/nest_asyncio seems to have been abandodend 

### Describe the solution you'd like

Remove nest_asyncio, and let bittensor users decide which asyncio loop they want to run. Perhaps even suggest (not mandate) running uvloop, since it consistently shows better results in benchmarks than CPython asyncio stdlib loop.

Seems like there was some attempt of this in the past https://github.com/opentensor/bittensor/pull/1501 for some reason (?) 

### Describe alternatives you've considered

_No response_

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/bittensor/__init__.py b/bittensor/__init__.py
--- a/bittensor/__init__.py
+++ b/bittensor/__init__.py
@@ -16,15 +16,28 @@
 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
+import os
+import warnings
 
 from rich.console import Console
 from rich.traceback import install
 
-# Install and apply nest asyncio to allow the async functions
-# to run in a .ipynb
-import nest_asyncio
 
-nest_asyncio.apply()
+if (NEST_ASYNCIO_ENV := os.getenv("NEST_ASYNCIO")) in ("1", None):
+    if NEST_ASYNCIO_ENV is None:
+        warnings.warn(
+            "NEST_ASYNCIO implicitly set to '1'. In the future, the default value will be '0'."
+            "If you use `nest_asyncio` make sure to add it explicitly to your project dependencies,"
+            "as it will be removed from `bittensor` package dependencies in the future."
+            "To silence this warning, explicitly set the environment variable, e.g. `export NEST_ASYNCIO=0`.",
+            DeprecationWarning,
+        )
+    # Install and apply nest asyncio to allow the async functions
+    # to run in a .ipynb
+    import nest_asyncio
+
+    nest_asyncio.apply()
+
 
 # Bittensor code and protocol version.
 __version__ = "7.0.0"


Test patch:
Repository: PaddlePaddle/PaddleOCR

Issue:
distributed training AttributeError:    DataParallel' object has no attribute 'head'
eval model::   0%|          | 0/74 [00:00<?, ?it/s]Traceback (most recent call last):
  File "tools/train.py", line 115, in <module>
    main(config, device, logger, vdl_writer)
  File "tools/train.py", line 92, in main
    eval_class, pre_best_model_dict, logger, vdl_writer)
  File "/paddle/PaddleOCR/tools/program.py", line 258, in train
    eval_class)
  File "/paddle/PaddleOCR/tools/program.py", line 334, in eval
    if "SRN" in str(model.head):
  File "/usr/local/python3.5.1/lib/python3.5/site-packages/paddle/fluid/dygraph/layers.py", line 1039, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataParallel' object has no attribute 'head'

command:     python3 -u -m paddle.distributed.launch --gpus '4,5,6,7'  tools/train.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml 


Discussion:
We fixed the problem, please update your dygraph branch code.

Resolving patch:
diff --git a/tools/program.py b/tools/program.py
--- a/tools/program.py
+++ b/tools/program.py
@@ -177,6 +177,8 @@ def train(config,
     model_average = False
     model.train()
 
+    use_srn = config['Architecture']['algorithm'] == "SRN"
+
     if 'start_epoch' in best_model_dict:
         start_epoch = best_model_dict['start_epoch']
     else:
@@ -195,7 +197,7 @@ def train(config,
                 break
             lr = optimizer.get_lr()
             images = batch[0]
-            if config['Architecture']['algorithm'] == "SRN":
+            if use_srn:
                 others = batch[-4:]
                 preds = model(images, others)
                 model_average = True
@@ -251,8 +253,12 @@ def train(config,
                         min_average_window=10000,
                         max_average_window=15625)
                     Model_Average.apply()
-                cur_metric = eval(model, valid_dataloader, post_process_class,
-                                  eval_class)
+                cur_metric = eval(
+                    model,
+                    valid_dataloader,
+                    post_process_class,
+                    eval_class,
+                    use_srn=use_srn)
                 cur_metric_str = 'cur metric, {}'.format(', '.join(
                     ['{}: {}'.format(k, v) for k, v in cur_metric.items()]))
                 logger.info(cur_metric_str)
@@ -316,7 +322,8 @@ def train(config,
     return
 
 
-def eval(model, valid_dataloader, post_process_class, eval_class):
+def eval(model, valid_dataloader, post_process_class, eval_class,
+         use_srn=False):
     model.eval()
     with paddle.no_grad():
         total_frame = 0.0
@@ -327,7 +334,8 @@ def eval(model, valid_dataloader, post_process_class, eval_class):
                 break
             images = batch[0]
             start = time.time()
-            if "SRN" in str(model.head):
+
+            if use_srn:
                 others = batch[-4:]
                 preds = model(images, others)
             else:


Test patch: