Skip to content

Commit

Permalink
papers
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Sep 30, 2024
1 parent b8f0abd commit bad8022
Show file tree
Hide file tree
Showing 11 changed files with 3,666 additions and 317 deletions.
15 changes: 8 additions & 7 deletions commune/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ def forward(self, argv=None):
if any([arg.startswith('--') for arg in argv]):
for arg in c.copy(argv):
if arg.startswith('--'):
key = arg[2:].split('=')[0]
if key in self.helper_fns:
new_argvs = self.argv()
new_argvs.remove(arg)
new_argvs = [key , new_argvs[0]]
return self.forward(new_argvs)
if '=' in arg:
key = arg[2:].split('=')[0]
if key in self.helper_fns:
new_argvs = self.argv()
new_argvs.remove(arg)
new_argvs = [key , new_argvs[0]]
return self.forward(new_argvs)
value = arg.split('=')[1]

else:
key = arg[2:]
value = True
Expand Down Expand Up @@ -84,6 +83,8 @@ def forward(self, argv=None):
module = argv.pop(0)
fn = argv.pop(0)



if isinstance(module, str):
module = c.get_module(module)
# module = self.base_module.from_object(module)
Expand Down
9 changes: 0 additions & 9 deletions commune/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def __init__(self,
# for the sake of simplicity, we'll just add all the extra kwargs to the task object
self.path = self.resolve_path(path) if path != None else None
self.status = 'pending' # pending, running, done
# save the task state


@property
def lifetime(self) -> float:
Expand All @@ -65,7 +63,6 @@ def state(self) -> dict:
'data': self.data,
}


def run(self):
"""Run the given work item"""
# Checks if future is canceled or if work item is stale
Expand All @@ -91,8 +88,6 @@ def run(self):
self.latency = self.end_time - self.start_time
self.data = data



def result(self) -> object:
return self.future.result()

Expand Down Expand Up @@ -124,7 +119,6 @@ def __lt__(self, other):
else:
raise TypeError(f"Cannot compare Task with {type(other)}")


NULL_ENTRY = (sys.maxsize, Task(None, (), {}))

class ThreadPoolExecutor(c.Module):
Expand Down Expand Up @@ -172,12 +166,9 @@ def is_empty(self):
def is_full(self):
return self.work_queue.full()


def default_priority_score(self):
# older scores are higher priority
return 1 # abs((self.start_time - c.time()))



def submit(self,
fn: Callable,
Expand Down
17 changes: 13 additions & 4 deletions commune/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def key(self):
def key(self, key: 'Key'):
if key == None:
key = self.server_name
self._key = key if hasattr(key, 'ss58_address') else c.get_key(key, create_if_not_exists=True)
if isinstance(key, str):
key = c.get_key(key, create_if_not_exists=True)

self._key = key
return self._key

@classmethod
Expand Down Expand Up @@ -1813,6 +1816,8 @@ def file2text(self, path = './',
'.git',
'.ipynb_checkpoints',
'package.lock',
'Cargo.lock',
'target/debug',
'node_modules'],
relative=True, **kwargs):
path = os.path.abspath(path)
Expand All @@ -1822,9 +1827,12 @@ def file2text(self, path = './',
continue
if any([folder in file for folder in avoid_folders]):
continue
with open(file, 'r') as f:
content = f.read()
file2text[file] = content
try:
with open(file, 'r') as f:
content = f.read()
file2text[file] = content
except Exception as e:
print(file)
if relative:
print(path)
return {k[len(path)+1:]:v for k,v in file2text.items()}
Expand Down Expand Up @@ -2797,6 +2805,7 @@ def simple2path(cls,
else:
module_filepath = dir_path + '/' + simple.replace('.', '/')
path_options += [module_filepath]

for p in path_options:
p = cls.resolve_extension(p)
if os.path.exists(p):
Expand Down
Loading

0 comments on commit bad8022

Please sign in to comment.