Skip to content

Conversation

@besteguney
Copy link
Collaborator

@besteguney besteguney commented Dec 7, 2024

In this pr, the initial Aioli algorithm is created for dynamic mixtures.

@github-actions
Copy link

github-actions bot commented Dec 11, 2024

✅ Result of Pytest Coverage

---------- coverage: platform linux, python 3.10.0-final-0 -----------

Name Stmts Miss Cover
mixtera/core/algo/ado/ado.py 375 171 54%
mixtera/core/algo/aioli/aioli.py 110 18 84%
mixtera/core/algo/dynamic_mixing/dynamic_mixing.py 32 3 91%
mixtera/core/client/local/local_stub.py 107 17 84%
mixtera/core/client/mixtera_client.py 126 31 75%
mixtera/core/client/server/server_stub.py 64 6 91%
mixtera/core/datacollection/datasets/croissant_dataset.py 16 3 81%
mixtera/core/datacollection/datasets/dataset.py 38 14 63%
mixtera/core/datacollection/datasets/dataset_type.py 7 0 100%
mixtera/core/datacollection/datasets/jsonl_dataset.py 58 9 84%
mixtera/core/datacollection/datasets/parquet_dataset.py 83 5 94%
mixtera/core/datacollection/datasets/web_dataset.py 39 7 82%
mixtera/core/datacollection/index/index.py 6 1 83%
mixtera/core/datacollection/index/index_collection.py 11 0 100%
mixtera/core/datacollection/index/index_utils.py 14 0 100%
mixtera/core/datacollection/index/parser/metadata_parser.py 51 7 86%
mixtera/core/datacollection/index/parser/parser_collection.py 80 18 78%
mixtera/core/datacollection/mixtera_data_collection.py 369 119 68%
mixtera/core/datacollection/property.py 7 0 100%
mixtera/core/datacollection/property_type.py 4 0 100%
mixtera/core/filesystem/filesystem.py 37 1 97%
mixtera/core/filesystem/local_filesystem.py 26 0 100%
mixtera/core/processing/execution_mode.py 4 0 100%
mixtera/core/processing/property_calculation/executor.py 22 2 91%
mixtera/core/processing/property_calculation/local_executor.py 68 14 79%
mixtera/core/query/chunk_distributor.py 248 171 31%
mixtera/core/query/mixture/arbitrary_mixture.py 12 1 92%
mixtera/core/query/mixture/dynamic_mixture.py 52 3 94%
mixtera/core/query/mixture/hierarchical_static_mixture.py 44 5 89%
mixtera/core/query/mixture/inferring_mixture.py 28 6 79%
mixtera/core/query/mixture/mixture.py 34 8 76%
mixtera/core/query/mixture/mixture_key.py 48 3 94%
mixtera/core/query/mixture/mixture_schedule.py 34 9 74%
mixtera/core/query/mixture/static_mixture.py 42 10 76%
mixtera/core/query/operators/_base.py 23 1 96%
mixtera/core/query/operators/select.py 107 3 97%
mixtera/core/query/query.py 54 0 100%
mixtera/core/query/query_cache.py 76 9 88%
mixtera/core/query/query_plan.py 18 2 89%
mixtera/core/query/query_result.py 378 91 76%
mixtera/core/query/result_chunk.py 296 114 61%
mixtera/hf/mixtera_hf_dataset.py 75 47 37%
mixtera/network/client/client_feedback.py 8 0 100%
mixtera/network/connection/server_connection.py 226 38 83%
mixtera/network/network_utils.py 90 10 89%
mixtera/network/server/entrypoint.py 22 22 0%
mixtera/network/server/server.py 203 74 64%
mixtera/network/server_task.py 17 0 100%
mixtera/tests/core/algo/ado/test_ado.py 167 0 100%
mixtera/tests/core/algo/aioli/test_aioli.py 73 0 100%
mixtera/tests/core/client/local/test_local_stub.py 198 1 99%
mixtera/tests/core/client/server/test_server_stub.py 147 0 100%
mixtera/tests/core/client/test_mixtera_client.py 66 0 100%
mixtera/tests/core/datacollection/datasets/test_dataset.py 0 0 100%
mixtera/tests/core/datacollection/datasets/test_jsonl_dataset.py 67 6 91%
mixtera/tests/core/datacollection/datasets/test_parquet_dataset.py 163 5 97%
mixtera/tests/core/datacollection/datasets/test_web_dataset.py 49 0 100%
mixtera/tests/core/datacollection/index/parser/test_parser_collection.py 81 2 98%
mixtera/tests/core/datacollection/index/test_index_utils.py 15 1 93%
mixtera/tests/core/datacollection/test_mixtera_data_collection.py 249 5 98%
mixtera/tests/core/datacollection/test_property_type.py 7 0 100%
mixtera/tests/core/filesystem/test_filesystem.py 47 0 100%
mixtera/tests/core/filesystem/test_local_filesystem.py 39 0 100%
mixtera/tests/core/processing/property_calculation/test_executor.py 22 0 100%
mixtera/tests/core/processing/property_calculation/test_local_executor.py 51 0 100%
mixtera/tests/core/processing/test_execution_mode.py 7 0 100%
mixtera/tests/core/query/operators/test_base.py 45 1 98%
mixtera/tests/core/query/operators/test_select.py 162 1 99%
mixtera/tests/core/query/test_chunk_distributor.py 113 1 99%
mixtera/tests/core/query/test_dynamic_mixture.py 120 0 100%
mixtera/tests/core/query/test_e2e.py 60 3 95%
mixtera/tests/core/query/test_mixture.py 20 1 95%
mixtera/tests/core/query/test_mixture_schedule.py 15 1 93%
mixtera/tests/core/query/test_query.py 143 4 97%
mixtera/tests/core/query/test_query_cache.py 85 4 95%
mixtera/tests/core/query/test_query_result.py 302 0 100%
mixtera/tests/core/query/test_result_chunk.py 195 1 99%
mixtera/tests/network/connection/test_server_connection.py 381 1 99%
mixtera/tests/network/server/test_server.py 186 0 100%
mixtera/tests/network/test_network_utils.py 165 1 99%
mixtera/tests/network/test_server_task.py 45 0 100%
mixtera/tests/utils/test_checkpoint.py 60 0 100%
mixtera/tests/utils/test_tokenizing_iterator.py 237 1 99%
mixtera/tests/utils/test_utils.py 95 1 99%
mixtera/torch/mixtera_torch_dataset.py 175 132 25%
mixtera/utils/checkpoint.py 22 0 100%
mixtera/utils/dataset_utils.py 104 82 21%
mixtera/utils/feedback.py 20 20 0%
mixtera/utils/prefetch_iterator.py 25 18 28%
mixtera/utils/tokenizing_iterator.py 136 7 95%
mixtera/utils/utils.py 232 76 67%
mixtera/utils/webdataset_utils.py 80 24 70%
TOTAL 8560 1473 83%
Coverage HTML written to
================== 324 passed, 1

@besteguney besteguney marked this pull request as ready for review December 12, 2024 14:10
Copy link
Contributor

@MaxiBoether MaxiBoether left a comment

Choose a reason for hiding this comment

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

Thank you, Beste. I checked the code on the level of understanding of the algorithm that I have. You are the expert on the actual logic. I just gave some small nitpicky remarks :) After fixing them and fixing CI, we can merge this and you can build on top of it. I think it would be good to test this with an actual training, to see how it behaves

Comment on lines 92 to 101

Args:
losses: A numpy array of losses per domain.
counts: A numpy array of counts per domain.
"""
num_incoming_domains = len(losses)
num_internal_domains = len(self.losses)
num_domains = max(num_incoming_domains, num_internal_domains)

if num_internal_domains < num_domains:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this doing anything more than the parent class? Similar to ADO, we definitely want a super() call here and only do additional work if necessary

self.aioli_diagonal = aioli_diagonal
self.domain_count = len(self.losses)
self.graph = np.zeros((self.domain_count, self.domain_count))
self.weights: np.ndarray = None # The latest weights after update steps have been completed.
Copy link
Contributor

Choose a reason for hiding this comment

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

if something can be none, the type is typically | None

Comment on lines 82 to 84
perturbed_domain = self.last_received_mixture % (self.domain_count + 1)
if perturbed_domain != self.domain_count:
self.graph[:, perturbed_domain] += self.losses - losses
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want some warmup logic here? Do you immediately start perturbing? Because imagine the very first client feedback, that will have update_at_client = True. Not sure if some checking here is needed.

Comment on lines 146 to 148
if self.weights is None:
self.weights = np.multiply(weights_init, np.exp(self.eta * self.graph.sum(axis=0)))
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

weights = weights_init if self.weights is None else self.weights
self.weights = np.multiply(weights, np.exp(...))

self.weights = np.multiply(self.weights, np.exp(self.eta * self.graph.sum(axis=0)))

logger.info(f"The new mixture proportions={self.weights/sum(self.weights)}. ")
self.weights = self.weights / sum(self.weights)
Copy link
Contributor

Choose a reason for hiding this comment

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

probably want np.sum for speed

Comment on lines 57 to 60
for i in range(self.domain_count):
weight_row = np.ones(self.domain_count) * (1 - self.one_hot_factor) / (self.domain_count - 1)
weight_row[i] = self.one_hot_factor
weight_matrix[i] = weight_row
Copy link
Contributor

Choose a reason for hiding this comment

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

if you can vectorize this for the entire matrix, that would of course be even better, but I don't know if this currently would be a major bottleneck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants