Removed some components,

also added the command env variables, now going to run inference.
This commit is contained in:
ArEnSc committed 2024-01-11 21:24:38 -05:00
1 parent 8709fa9c8a
commit 2d52ac0fa9
8 files changed
+56 -37

No files matched your search

@@ -202,21 +202,24 @@ mod tests {
let upload_path = "upload_path".to_string();
let lora_upload_path = "lora_upload_path".to_string();
let checkpoint = "checkpoint".to_string();
let type_of_inference = "type_of_inference".to_string();
let args = GenericInferenceArgs {
inference_category: Some(InferenceCategoryAbbreviated::ImageGeneration),
args: Some(PolymorphicInferenceArgs::Ig(StableDiffusionArgs {
maybe_video_source: Some(video_media_token),
maybe_image_source: Some(image_media_token),
maybe_sd_model_token: Some(sd_model_token),
maybe_lora_model_token: Some(lora_model_token),
maybe_height: Some(512),
maybe_width: Some(512),
maybe_cfg_scale: Some(7),
maybe_prompt: Some(prompt),
maybe_a_prompt: Some(a_prompt),
maybe_n_prompt: Some(n_prompt),
maybe_batch_count: Some(1),
maybe_batch_size: Some(1),
maybe_number_of_samples: Some(25),
maybe_seed: Some(seed),
maybe_upload_path: Some(upload_path),
maybe_lora_upload_path: Some(lora_upload_path),
inference_type: Some(checkpoint)
type_of_inference: type_of_inference
})),
};
@@ -45,10 +45,6 @@ pub struct StableDiffusionArgs {
#[serde(skip_serializing_if = "Option::is_none")]
pub maybe_prompt: Option<String>,
#[serde(rename = "ap")]
#[serde(skip_serializing_if = "Option::is_none")]
pub maybe_a_prompt: Option<String>,
#[serde(rename = "np")]
#[serde(skip_serializing_if = "Option::is_none")]
pub maybe_n_prompt: Option<String>,
@@ -109,8 +109,8 @@ RERENDER_INFERENCE_EXECUTABLE_OR_COMMAND="venv/bin/python rerender.py"
# STABLE DIFFUSION #
# #
# ================================= #
STABLE_DIFFUSION_INFERENCE_COMMAND="/home/tensor/code/storyteller/storyteller-ml/image-gen"
STABLE_DIFFUSION_INFERENCE_ROOT_DIRECTORY="/home/tensor/code/storyteller/storyteller-ml/image_generation/Storyteller-Studio-Filter/"
STABLE_DIFFUSION_INFERENCE_COMMAND="venv/bin/python main.py"
# ================================= #
# #
@@ -2,7 +2,7 @@ use enums::by_table::generic_inference_jobs::inference_model_type::InferenceMode
use mysql_queries::queries::generic_inference::job::list_available_generic_inference_jobs::AvailableInferenceJob;
use crate::job::job_loop::job_success_result::JobSuccessResult;
use crate::job::job_loop::process_single_job_error::ProcessSingleJobError;
use crate::job::job_types::image_generation::sd::process_job::process_job;
use crate::job::job_types::image_generation::sd::process_job::process_job_selection;
use crate::job_dependencies::JobDependencies;
use crate::job::job_types::image_generation::sd::process_job::StableDiffusionProcessArgs;
use errors::anyhow;
@@ -30,5 +30,5 @@ pub async fn dispatch_sd_job(job_dependencies: &JobDependencies, job: &Available
job_dependencies,
job,
};
process_job(args).await
process_job_selection(args).await
}
@@ -1,4 +1,5 @@
pub mod process_job;
pub mod model_downloaders;
pub mod sd_inference_command;
pub mod stable_diffusion_dependencies;
@@ -63,7 +63,39 @@ pub async fn sd_args_from_job(
Ok(stable_diffusion_args)
}
pub async fn process_job(
pub async fn process_job_selection (args: StableDiffusionProcessArgs<'_>
) -> Result<JobSuccessResult, ProcessSingleJobError> {
let job = args.job;
let sd_args = sd_args_from_job(&args).await?;
if sd_args.type_of_inference == "inference" {
process_job_inference(args).await
}
else if sd_args.type_of_inference == "lora" {
process_job_lora(args).await
}
else if sd_args.type_of_inference == "checkpoint"{
process_job_inference(args).await
}
else {
Err(ProcessSingleJobError::Other(anyhow!("inference type doesn't exist!")))
}
}
pub async fn process_job_checkpoint(args: StableDiffusionProcessArgs<'_>) -> Result<JobSuccessResult, ProcessSingleJobError> {
Ok(JobSuccessResult {
maybe_result_entity: None,
inference_duration: Duration::from_secs(0),
})
}
pub async fn process_job_lora(args: StableDiffusionProcessArgs<'_>) -> Result<JobSuccessResult, ProcessSingleJobError> {
Ok(JobSuccessResult {
maybe_result_entity: None,
inference_duration: Duration::from_secs(0),
})
}
pub async fn process_job_inference(
args: StableDiffusionProcessArgs<'_>
) -> Result<JobSuccessResult, ProcessSingleJobError> {
let job = args.job;
@@ -83,9 +83,8 @@ pub struct InferenceArgs<P: AsRef<Path>> {
pub cfg_scale:i32,
pub seed:i32,
pub lora_path:P,
pub check_point:P,
pub checkpoint_path:P,
pub vae:P,
pub batch_size:i32,
pub batch_count:i32,
}
@@ -117,16 +116,12 @@ impl StableDiffusionInferenceCommand {
let maybe_inference_command = easyenv::get_env_string_optional(
"STABLE_DIFFUSION_INFERENCE_COMMAND");
// Optional, eg. `./infer.py`. Typically we'll use the command form instead.
let maybe_inference_executable = easyenv::get_env_pathbuf_optional(
"STABLE_DIFFUSION_INFERENCE_EXECUTABLE");
let executable_or_command = match maybe_inference_command {
Some(command) => ExecutableOrCommand::Command(command),
None => match maybe_inference_executable {
Some(executable) => ExecutableOrCommand::Executable(executable),
None => return Err(anyhow!("neither command nor executable passed")),
},
None => {
return Err(anyhow!("neither command nor executable passed"));
}
};
let maybe_virtual_env_activation_command = easyenv::get_env_string_optional(
@@ -204,19 +199,16 @@ impl StableDiffusionInferenceCommand {
// ===== Begin Python Args =====
command.push_str("--prompt ");
command.push_str(&args.prompt.as_ref().to_string_lossy());
command.push_str(" --result_dir ");
command.push_str(&args.work_dir.as_ref().to_string_lossy());
command.push_str(" --result_file ");
command.push_str(&args.output_file.as_ref().to_string_lossy());
command.push_str(" --stderr_output_file ");
command.push_str(&args.stderr_output_file.as_ref().to_string_lossy());
command.push_str(" --prompt ");
command.push_str(&args.prompt.as_ref().to_string_lossy());
command.push_str(" --negative_prompt ");
command.push_str(&args.negative_prompt.as_ref().to_string_lossy());
@@ -242,14 +234,11 @@ impl StableDiffusionInferenceCommand {
command.push_str(&args.lora_path.as_ref().to_string_lossy());
command.push_str(" --check_point ");
command.push_str(&args.check_point.as_ref().to_string_lossy());
command.push_str(&args.checkpoint_path.as_ref().to_string_lossy());
command.push_str(" --vae ");
command.push_str(&args.vae.as_ref().to_string_lossy());
command.push_str(" --batch_size ");
command.push_str(&args.batch_size.to_string());
command.push_str(" --batch_count ");
command.push_str(&args.batch_count.to_string());
@@ -109,7 +109,6 @@ pub struct EnqueueImageGenRequest {
maybe_sd_model_token: Option<String>,
maybe_lora_model_token: Option<String>,
maybe_prompt: Option<String>,
maybe_a_prompt: Option<String>,
maybe_n_prompt: Option<String>,
maybe_seed: Option<i64>,
maybe_width: Option<i32>,
@@ -189,8 +188,10 @@ pub async fn enqueue_image_generation_request(
) -> Result<HttpResponse, EnqueueImageGenRequestError> {
// TODO: Brandon need to figure out premium vs not premium
let mut maybe_user_token: Option<UserToken> = None;
let visbility = enums::common::visibility::Visibility::Public;
let mut mysql_connection = server_state.mysql_pool.acquire().await.map_err(|err| {
warn!("MySql pool error: {:?}", err);
EnqueueImageGenRequestError::ServerError
@@ -316,7 +317,6 @@ pub async fn enqueue_image_generation_request(
let lora_token = ModelWeightToken(request.maybe_lora_model_token.clone().unwrap_or_default());
let a_prompt = request.maybe_a_prompt.clone().unwrap_or_default();
let n_prompt = request.maybe_n_prompt.clone().unwrap_or_default();
// we can only do 1 upload type at a time.
@@ -333,12 +333,10 @@ pub async fn enqueue_image_generation_request(
let type_of_inference = request.type_of_inference.to_string().clone();
let inference_args = StableDiffusionArgs {
maybe_sd_model_token: Some(sd_weight_token),
maybe_lora_model_token: Some(lora_token),
maybe_prompt: Some(request.maybe_prompt.clone().unwrap_or_default()),
maybe_a_prompt: Some(a_prompt),
maybe_n_prompt: Some(n_prompt),
maybe_seed: Some(seed),
maybe_upload_path: Some(upload_path),