Spaces:
Sleeping
Sleeping
Commit
·
033f68d
1
Parent(s):
f3f5382
random recipes + loads models initially
Browse files
evolutiontransformer/worker.py
CHANGED
|
@@ -257,6 +257,8 @@ def merge_models_task(
|
|
| 257 |
|
| 258 |
@celery_app.task(name="tasks.get_all_models")
|
| 259 |
def get_all_models_task(session_id: str) -> List[str]:
|
|
|
|
|
|
|
| 260 |
base_models = BASE_MODELS_NAMES
|
| 261 |
session_models = get_session_models(session_id)
|
| 262 |
all_models = list(set(base_models + session_models))
|
|
|
|
| 257 |
|
| 258 |
@celery_app.task(name="tasks.get_all_models")
|
| 259 |
def get_all_models_task(session_id: str) -> List[str]:
|
| 260 |
+
load_base_models_if_needed()
|
| 261 |
+
|
| 262 |
base_models = BASE_MODELS_NAMES
|
| 263 |
session_models = get_session_models(session_id)
|
| 264 |
all_models = list(set(base_models + session_models))
|
frontend/src/components/Recipe.jsx
CHANGED
|
@@ -29,23 +29,49 @@ const Recipe = ({
|
|
| 29 |
setModelLayerCounts(counts);
|
| 30 |
}, [selectedModel1, selectedModel2]);
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
const initializeLayerRecipe = useCallback(() => {
|
| 33 |
const recipe = [];
|
| 34 |
for (let i = 0; i < numLayers; i++) {
|
| 35 |
-
recipe.push([[1, 0, 0
|
| 36 |
}
|
| 37 |
setLayerRecipe(recipe);
|
| 38 |
}, [numLayers, setLayerRecipe]);
|
| 39 |
|
| 40 |
useEffect(() => {
|
| 41 |
-
if (layerRecipe.length
|
|
|
|
| 42 |
initializeLayerRecipe();
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
-
}, [numLayers, layerRecipe.length, initializeLayerRecipe]);
|
| 45 |
|
| 46 |
const addBlockToLayer = (layerIndex) => {
|
| 47 |
const newRecipe = [...layerRecipe];
|
| 48 |
-
const newBlock = [1, 1, 0.5];
|
| 49 |
newRecipe[layerIndex] = [...newRecipe[layerIndex], newBlock];
|
| 50 |
setLayerRecipe(newRecipe);
|
| 51 |
};
|
|
@@ -68,7 +94,12 @@ const Recipe = ({
|
|
| 68 |
block[1] = value;
|
| 69 |
block[0] = 1;
|
| 70 |
} else if (field === "sourceLayer") {
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
} else if (field === "percentage") {
|
| 73 |
block[2] = value / 100;
|
| 74 |
}
|
|
@@ -98,6 +129,44 @@ const Recipe = ({
|
|
| 98 |
return modelValue === 0 ? "Model 1" : "Model 2";
|
| 99 |
};
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
const getBlockId = (layerIndex, blockIndex) => {
|
| 102 |
return `${layerIndex}-${blockIndex}`;
|
| 103 |
};
|
|
@@ -127,6 +196,28 @@ const Recipe = ({
|
|
| 127 |
</svg>
|
| 128 |
</div>
|
| 129 |
<h2 className="text-xl font-bold text-foreground">Layer Recipe</h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
</div>
|
| 131 |
|
| 132 |
<div className="space-y-8">
|
|
|
|
| 29 |
setModelLayerCounts(counts);
|
| 30 |
}, [selectedModel1, selectedModel2]);
|
| 31 |
|
| 32 |
+
const adjustLayerRecipe = useCallback(() => {
|
| 33 |
+
const currentLength = layerRecipe.length;
|
| 34 |
+
|
| 35 |
+
if (currentLength === numLayers) {
|
| 36 |
+
return; // No change needed
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
let newRecipe = [...layerRecipe];
|
| 40 |
+
|
| 41 |
+
if (currentLength < numLayers) {
|
| 42 |
+
// Add new layers to the end
|
| 43 |
+
for (let i = currentLength; i < numLayers; i++) {
|
| 44 |
+
newRecipe.push([[1, 0, 1.0]]);
|
| 45 |
+
}
|
| 46 |
+
} else {
|
| 47 |
+
// Remove layers from the end
|
| 48 |
+
newRecipe = newRecipe.slice(0, numLayers);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
setLayerRecipe(newRecipe);
|
| 52 |
+
}, [numLayers, layerRecipe, setLayerRecipe]);
|
| 53 |
+
|
| 54 |
const initializeLayerRecipe = useCallback(() => {
|
| 55 |
const recipe = [];
|
| 56 |
for (let i = 0; i < numLayers; i++) {
|
| 57 |
+
recipe.push([[1, 0, 1.0]]);
|
| 58 |
}
|
| 59 |
setLayerRecipe(recipe);
|
| 60 |
}, [numLayers, setLayerRecipe]);
|
| 61 |
|
| 62 |
useEffect(() => {
|
| 63 |
+
if (layerRecipe.length === 0) {
|
| 64 |
+
// Initialize if recipe is empty
|
| 65 |
initializeLayerRecipe();
|
| 66 |
+
} else if (layerRecipe.length !== numLayers) {
|
| 67 |
+
// Adjust existing recipe
|
| 68 |
+
adjustLayerRecipe();
|
| 69 |
}
|
| 70 |
+
}, [numLayers, layerRecipe.length, initializeLayerRecipe, adjustLayerRecipe]);
|
| 71 |
|
| 72 |
const addBlockToLayer = (layerIndex) => {
|
| 73 |
const newRecipe = [...layerRecipe];
|
| 74 |
+
const newBlock = [1, Math.random() < 0.5 ? 0 : 1, 0.5];
|
| 75 |
newRecipe[layerIndex] = [...newRecipe[layerIndex], newBlock];
|
| 76 |
setLayerRecipe(newRecipe);
|
| 77 |
};
|
|
|
|
| 94 |
block[1] = value;
|
| 95 |
block[0] = 1;
|
| 96 |
} else if (field === "sourceLayer") {
|
| 97 |
+
// Ensure layer value is within valid range (1 to max layers for selected model)
|
| 98 |
+
const selectedModel = block[1];
|
| 99 |
+
const maxLayers =
|
| 100 |
+
selectedModel === 0 ? modelLayerCounts.model1 : modelLayerCounts.model2;
|
| 101 |
+
const maxLayerValue = maxLayers === "N/A" ? 1 : maxLayers;
|
| 102 |
+
block[0] = Math.max(1, Math.min(maxLayerValue, value));
|
| 103 |
} else if (field === "percentage") {
|
| 104 |
block[2] = value / 100;
|
| 105 |
}
|
|
|
|
| 129 |
return modelValue === 0 ? "Model 1" : "Model 2";
|
| 130 |
};
|
| 131 |
|
| 132 |
+
const generateRandomRecipe = () => {
|
| 133 |
+
const randomEmbedding1 = Math.random();
|
| 134 |
+
const randomEmbedding2 = 1 - randomEmbedding1;
|
| 135 |
+
setEmbeddingLambdas([randomEmbedding1, randomEmbedding2]);
|
| 136 |
+
|
| 137 |
+
const randomLinear1 = Math.random();
|
| 138 |
+
const randomLinear2 = 1 - randomLinear1;
|
| 139 |
+
setLinearLambdas([randomLinear1, randomLinear2]);
|
| 140 |
+
|
| 141 |
+
const newRecipe = [];
|
| 142 |
+
for (let i = 0; i < numLayers; i++) {
|
| 143 |
+
const numBlocks = Math.floor(Math.random() * 5) + 1;
|
| 144 |
+
const layer = [];
|
| 145 |
+
|
| 146 |
+
const weights = [];
|
| 147 |
+
for (let j = 0; j < numBlocks; j++) {
|
| 148 |
+
weights.push(Math.random());
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
const totalWeight = weights.reduce((sum, w) => sum + w, 0);
|
| 152 |
+
const normalizedWeights = weights.map((w) => w / totalWeight);
|
| 153 |
+
|
| 154 |
+
for (let j = 0; j < numBlocks; j++) {
|
| 155 |
+
const randomModel = Math.floor(Math.random() * 2); // 0 or 1
|
| 156 |
+
const maxLayers =
|
| 157 |
+
randomModel === 0 ? modelLayerCounts.model1 : modelLayerCounts.model2;
|
| 158 |
+
const maxLayerValue = maxLayers === "N/A" ? 1 : maxLayers;
|
| 159 |
+
|
| 160 |
+
const randomLayer = Math.floor(Math.random() * maxLayerValue) + 1;
|
| 161 |
+
layer.push([randomLayer, randomModel, normalizedWeights[j]]);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
newRecipe.push(layer);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
setLayerRecipe(newRecipe);
|
| 168 |
+
};
|
| 169 |
+
|
| 170 |
const getBlockId = (layerIndex, blockIndex) => {
|
| 171 |
return `${layerIndex}-${blockIndex}`;
|
| 172 |
};
|
|
|
|
| 196 |
</svg>
|
| 197 |
</div>
|
| 198 |
<h2 className="text-xl font-bold text-foreground">Layer Recipe</h2>
|
| 199 |
+
<button
|
| 200 |
+
onClick={generateRandomRecipe}
|
| 201 |
+
className="ml-4 px-4 py-2 bg-gradient-to-r from-accent-500 to-primary-500 text-white font-medium rounded-lg hover:from-accent-600 hover:to-primary-600 transition-all duration-200 flex items-center space-x-2 text-sm"
|
| 202 |
+
>
|
| 203 |
+
<svg
|
| 204 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 205 |
+
width="16"
|
| 206 |
+
height="16"
|
| 207 |
+
viewBox="0 0 24 24"
|
| 208 |
+
fill="none"
|
| 209 |
+
stroke="currentColor"
|
| 210 |
+
strokeWidth="2"
|
| 211 |
+
strokeLinecap="round"
|
| 212 |
+
strokeLinejoin="round"
|
| 213 |
+
>
|
| 214 |
+
<path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8" />
|
| 215 |
+
<path d="M21 3v5h-5" />
|
| 216 |
+
<path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16" />
|
| 217 |
+
<path d="M3 21v-5h5" />
|
| 218 |
+
</svg>
|
| 219 |
+
<span>Random Recipe</span>
|
| 220 |
+
</button>
|
| 221 |
</div>
|
| 222 |
|
| 223 |
<div className="space-y-8">
|