Skip to content

feat: add precision option (fp32/fp16/bf16)#44

Open
NULL204 wants to merge 1 commit into
EutropicAI:mainfrom
NULL204:main
Open

feat: add precision option (fp32/fp16/bf16)#44
NULL204 wants to merge 1 commit into
EutropicAI:mainfrom
NULL204:main

Conversation

@NULL204

@NULL204 NULL204 commented Jun 16, 2026

Copy link
Copy Markdown
Member

Add a precision config field (fp32/fp16/bf16, default fp32) and map it to cccv's fp16/bf16 arguments. bf16 avoids the fp16 numerical overflow that yields NaN output on some transformer models, at the same VRAM savings as fp16.

Add a precision config field (fp32/fp16/bf16, default fp32) and map it to
cccv's fp16/bf16 arguments. bf16 avoids the fp16 numerical overflow that
yields NaN output on some transformer models, at the same VRAM savings as
fp16.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 16, 2026 16:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds configurable numeric precision to SR configuration and wires it through model initialization to enable fp16/bf16 execution modes.

Changes:

  • Introduces precision to SRConfig with validation and a default of "fp32".
  • Passes precision through to AutoModel.from_pretrained via fp16/bf16 flags.
  • Adds tests for valid/invalid precision values and updates config generation to include precision.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
tests/test_config.py Adds unit tests to validate precision serialization/defaulting and invalid values.
scripts/gen_config.py Includes precision in generated config output.
Final2x_core/config.py Adds precision field and a validator restricting allowed values.
Final2x_core/SRclass.py Maps precision to model init flags (fp16/bf16).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Final2x_core/config.py
pretrained_model_name: Union[ConfigType, str]
device: str
use_tile: Optional[bool] = None
precision: str = "fp32" # "fp32" | "fp16" | "bf16"
Comment thread Final2x_core/config.py
Comment on lines +66 to +71
@field_validator("precision")
def precision_match(cls, v: str) -> str:
precision_list = ["fp32", "fp16", "bf16"]
if v not in precision_list:
raise ValueError(f"precision must be one of {precision_list}")
return v
Comment thread Final2x_core/SRclass.py
Comment on lines +29 to +30
fp16=(self.config.precision == "fp16"),
bf16=(self.config.precision == "bf16"),
Comment thread Final2x_core/config.py
def precision_match(cls, v: str) -> str:
precision_list = ["fp32", "fp16", "bf16"]
if v not in precision_list:
raise ValueError(f"precision must be one of {precision_list}")
Comment thread tests/test_config.py
Comment on lines +29 to +39
def test_precision_fp16(self) -> None:
config: SRConfig = SRConfig.from_yaml(CONFIG_PATH)
config.precision = "fp16"
config = SRConfig.from_json_str(config.model_dump_json())
assert config.precision == "fp16"

def test_precision_bf16(self) -> None:
config: SRConfig = SRConfig.from_yaml(CONFIG_PATH)
config.precision = "bf16"
config = SRConfig.from_json_str(config.model_dump_json())
assert config.precision == "bf16"

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new 'precision' configuration option ('fp32', 'fp16', 'bf16') to the super-resolution configuration ('SRConfig') and model initialization, along with corresponding validation and unit tests. Feedback suggests converting the precision input string to lowercase during validation to make it case-insensitive and more robust.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread Final2x_core/config.py
Comment on lines +67 to +71
def precision_match(cls, v: str) -> str:
precision_list = ["fp32", "fp16", "bf16"]
if v not in precision_list:
raise ValueError(f"precision must be one of {precision_list}")
return v

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To make the configuration more robust and user-friendly, consider converting the input precision string to lowercase before validation. This prevents validation failures if a user specifies uppercase values like FP16 or BF16 in their configuration file.

Suggested change
def precision_match(cls, v: str) -> str:
precision_list = ["fp32", "fp16", "bf16"]
if v not in precision_list:
raise ValueError(f"precision must be one of {precision_list}")
return v
def precision_match(cls, v: str) -> str:
v = v.lower()
precision_list = ["fp32", "fp16", "bf16"]
if v not in precision_list:
raise ValueError(f"precision must be one of {precision_list}")
return v

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.

2 participants