Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ai): add pipelines optimization flags #3013

Merged
merged 3 commits into from
Apr 16, 2024
Merged

Conversation

rickstaa
Copy link
Contributor

@rickstaa rickstaa commented Apr 15, 2024

Warning

Do not merge before livepeer/ai-worker#61.

What does this pull request do? Explain your changes. (required)

This commit adds a new OptimizationFlags field to the aiModels config so that users can forward optimization environment variables to the ai-worker for more information see livepeer/ai-worker#61.

Specific updates (required)

  • New OptimizationFlags field added to aiModels config.
  • Flags forwaded to the ai-worker Warm function.
  • A warning is thrown when users try to use the optimizationFlags with non warm containers.

How did you test each of these updates (required)

  1. Ensured the package builds.
  2. Ensured tests.sh were succesfull.
  3. Spung up off-chain broadcaster.
  4. Spung up off-chain orchestrator with SFAST optimization flag in the models configuration file.
[
    {
        "pipeline": "image-to-video",
        "model_id": "stabilityai/stable-video-diffusion-img2vid-xt-1-1",
        "price_per_unit": 3390842,
        "warm": true,
        "optimization_flags": {
            "SFAST": "true",
            "SOME": true
        }
    }
]
  1. Let the ImageToVideo container warmup and check the container logs to see that SFAST is used and the model is pre-traced.
  2. Send a ImageToVideo request to the broadcaster and checked that it stilled worked.

Does this pull request close any open issues?

No.

Checklist:

This commit adds a new `OptimizationFlags` field to the `aiModels`
config so that users can forward optimization environment variables to
the [ai-worker]([email protected]:livepeer/ai-worker.git) for more
information see livepeer/ai-worker#61.
@github-actions github-actions bot added the AI Issues and PR related to the AI-video branch. label Apr 15, 2024
@rickstaa
Copy link
Contributor Author

rickstaa commented Apr 15, 2024

@yondonfu, is there a specific reason why the binary execution proceeds even when an AIModelConfig is not specified? I encountered this issue while trying to activate flags for containers that don't start warm, as I wanted to pass Optimization flags directly to the AIWorker constructor.

if *cfg.AIModels != "" {
configs, err := core.ParseAIModelConfigs(*cfg.AIModels)
if err != nil {
glog.Error("Error parsing -aiModels: %v", err)
return
}
for _, config := range configs {
modelConstraint := &core.ModelConstraint{Warm: config.Warm}
// If the config contains a URL we call Warm() anyway because AIWorker will just register
// the endpoint for an external container
if config.Warm || config.URL != "" {
endpoint := worker.RunnerEndpoint{URL: config.URL, Token: config.Token}
if err := n.AIWorker.Warm(ctx, config.Pipeline, config.ModelID, endpoint); err != nil {
glog.Errorf("Error AI worker warming %v container: %v", config.Pipeline, err)
return
}
}
switch config.Pipeline {
case "text-to-image":
_, ok := constraints[core.Capability_TextToImage]
if !ok {
aiCaps = append(aiCaps, core.Capability_TextToImage)
constraints[core.Capability_TextToImage] = &core.Constraints{
Models: make(map[string]*core.ModelConstraint),
}
}
constraints[core.Capability_TextToImage].Models[config.ModelID] = modelConstraint
n.SetBasePriceForCap("default", core.Capability_TextToImage, config.ModelID, big.NewRat(config.PricePerUnit, config.PixelsPerUnit))
case "image-to-image":
_, ok := constraints[core.Capability_ImageToImage]
if !ok {
aiCaps = append(aiCaps, core.Capability_ImageToImage)
constraints[core.Capability_ImageToImage] = &core.Constraints{
Models: make(map[string]*core.ModelConstraint),
}
}
constraints[core.Capability_ImageToImage].Models[config.ModelID] = modelConstraint
n.SetBasePriceForCap("default", core.Capability_ImageToImage, config.ModelID, big.NewRat(config.PricePerUnit, config.PixelsPerUnit))
case "image-to-video":
_, ok := constraints[core.Capability_ImageToVideo]
if !ok {
aiCaps = append(aiCaps, core.Capability_ImageToVideo)
constraints[core.Capability_ImageToVideo] = &core.Constraints{
Models: make(map[string]*core.ModelConstraint),
}
}
constraints[core.Capability_ImageToVideo].Models[config.ModelID] = modelConstraint
n.SetBasePriceForCap("default", core.Capability_ImageToVideo, config.ModelID, big.NewRat(config.PricePerUnit, config.PixelsPerUnit))
}
}
}
defer func() {
ctx, cancel := context.WithTimeout(context.Background(), aiWorkerContainerStopTimeout)
defer cancel()
if err := n.AIWorker.Stop(ctx); err != nil {
glog.Errorf("Error stopping AI worker containers: %v", err)
return
}
glog.Infof("Stopped AI worker containers")
}()
}

@rickstaa rickstaa requested a review from yondonfu April 15, 2024 15:02
@rickstaa
Copy link
Contributor Author

Requires livepeer/ai-worker#61.

@yondonfu
Copy link
Member

@rickstaa

is there a specific reason why the binary execution proceeds even when an AIModelConfig is not specified?

I think it would sense to require a config file for -aiModels now because the config file is not only used to warm models, but also for specifying prices and determining which models to advertise during capability discovery. Prior to using the config file for configuring prices and capability discovery, the config file was left as optional because the O would just try to execute any request given a model ID. But now, since models have prices and have to be explicitly advertised, the config file is necessary.

Copy link
Member

@yondonfu yondonfu left a comment

Choose a reason for hiding this comment

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

Noting for the thread that this will need a go mod update to use the latest version of ai-worker once it is merged.

cmd/livepeer/starter/starter.go Outdated Show resolved Hide resolved
cmd/livepeer/starter/starter.go Outdated Show resolved Hide resolved
This commit ensures that the https://github.com/livepeer/ai-worker
dependency is on the latest commit that includes the new optimization
flags feature (see livepeer/ai-worker#61).
@rickstaa
Copy link
Contributor Author

@rickstaa

is there a specific reason why the binary execution proceeds even when an AIModelConfig is not specified?

I think it would sense to require a config file for -aiModels now because the config file is not only used to warm models, but also for specifying prices and determining which models to advertise during capability discovery. Prior to using the config file for configuring prices and capability discovery, the config file was left as optional because the O would just try to execute any request given a model ID. But now, since models have prices and have to be explicitly advertised, the config file is necessary.

Ah thanks for the explanation. Makes sense. I will change the behavoir!

This commit ensures that the `optimzation flag not supported` warning
is shown for each model that is not loaded warm.
@rickstaa rickstaa merged commit 9502ea0 into ai-video Apr 16, 2024
8 of 9 checks passed
@rickstaa rickstaa deleted the add_optimization_flags branch April 16, 2024 14:19
rickstaa added a commit that referenced this pull request Apr 16, 2024
This commit adds a new section explaining the new `optimization_flags` that were enabled
#3013.
rickstaa added a commit that referenced this pull request Apr 16, 2024
This commit adds a new section explaining the new `optimization_flags` that were enabled
#3013.
rickstaa added a commit that referenced this pull request Apr 16, 2024
This commit adds a new section explaining the new `optimization_flags` that were enabled
#3013.
rickstaa added a commit that referenced this pull request Apr 16, 2024
This commit adds a new section explaining the new `optimization_flags` that were enabled
#3013.
@rickstaa rickstaa mentioned this pull request Jun 10, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI Issues and PR related to the AI-video branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants