Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@booxter
Copy link
Contributor

@booxter booxter commented Aug 8, 2024

No description provided.

@booxter
Copy link
Contributor Author

booxter commented Aug 8, 2024

This is in context of #2021 but I'm not sure at this point we shouldn't just list() when passing any data coming from click that has to be a list.

@booxter
Copy link
Contributor Author

booxter commented Aug 8, 2024

This works but ultimately, this is just how click works. We should be aware of this and deal accordingly (either accept tuples everywhere, or cast before passing.)

@booxter booxter closed this Aug 8, 2024
@RobotSail RobotSail reopened this Aug 14, 2024
@RobotSail RobotSail marked this pull request as ready for review August 14, 2024 17:56
@mergify mergify bot added the ci-failure PR has at least one CI failure label Aug 14, 2024
@RobotSail
Copy link
Member

This PR is still a blocker for 0.18.0, since even with the fix provided in instructlab/training#162, we still get a warning from Pydantic about passing a tuple to a field that expects a list[str]. For this reason, I've added the blocker-proposed tag as this does not directly impede functionality, but it removes one more thing that may confuse users.

@RobotSail RobotSail force-pushed the cast-lora-modules-to-list branch from 5cca2e9 to fdbbf13 Compare August 14, 2024 18:10
@mergify mergify bot added ci-failure PR has at least one CI failure and removed ci-failure PR has at least one CI failure labels Aug 14, 2024
@booxter
Copy link
Contributor Author

booxter commented Aug 14, 2024

@RobotSail do you have a warning message from pydantic to look at?

@RobotSail
Copy link
Member

@booxter

/opt/app-root/lib64/python3.11/site-packages/pydantic/main.py:364: UserWarning: Pydantic serializer warnings:
  Expected `list[str]` but got `tuple` - serialized value may not be as expected
  return self.__pydantic_serializer__.to_python(

@booxter
Copy link
Contributor Author

booxter commented Aug 14, 2024

This looks like it comes from pydantic-core Rust implementation:

    pub fn on_fallback_ser<S: serde::ser::Serializer>(
        &self,
        field_type: &str,
        value: &Bound<'_, PyAny>,
        extra: &Extra,
    ) -> Result<(), S::Error> {
        // special case for None as it's very common e.g. as a default value
        if value.is_none() {
            Ok(())
        } else if extra.check.enabled() {
            // note: I think this should never actually happen since we use `to_python(..., mode='json')` during
            // JSON serialisation to "try" union branches, but it's here for completeness/correctness
            // in particular, in future we could allow errors instead of warnings on fallback
            Err(S::Error::custom(UNEXPECTED_TYPE_SER_MARKER))
        } else {
            self.fallback_warning(field_type, value);
            Ok(())
        }
    }

    fn fallback_warning(&self, field_type: &str, value: &Bound<'_, PyAny>) {
        if self.mode != WarningsMode::None {
            let type_name = value
                .get_type()
                .qualname()
                .unwrap_or_else(|_| PyString::new_bound(value.py(), "<unknown python object>"));

            let input_str = safe_repr(value);
            let mut value_str = String::with_capacity(100);
            value_str.push_str("with value `");
            crate::errors::write_truncated_to_50_bytes(&mut value_str, input_str.to_cow())
                .expect("Writing to a `String` failed");
            value_str.push('`');

            self.add_warning(format!(
                "Expected `{field_type}` but got `{type_name}` {value_str} - serialized value may not be as expected"
            ));
        }
    }

There's apparently a flag to disable these warnings (though I don't know if it's available or whether it's ok to suppress these messages), but clearly the library prefers that list fields receives lists, even if it will grudgingly accept tuples and other iterables. (I think pydantic should have explained it better in their docs. There, it just says that either of the types is fine, with no caveats.)

We can land this for now, but I think other options that are "lists" that come from click options will also be tuples, and should also be converted to lists (though it assumes we use list types for all models - which may not be the case: using tuple types is as legit - in this case, warnings would be raised if we cast to list!)

I think post-0.18 we should revisit this issue more broadly for all options and all libraries we have. @RobotSail I suggest a tracking issue is reported to follow up later.

@booxter booxter changed the title DNM Enforce list type for lora-target-modules Enforce list type for lora-target-modules Aug 14, 2024
@booxter
Copy link
Contributor Author

booxter commented Aug 15, 2024

@RobotSail any idea why CI was cancelled here?

@RobotSail
Copy link
Member

@booxter It seems like one of the tests in the functional tests is breaking CI - not sure why it was cancelled.

@ktam3
Copy link

ktam3 commented Aug 28, 2024

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Aug 28, 2024

rebase

❌ Unable to rebase: user ktam3 is unknown.

Details

Please make sure ktam3 has logged in Mergify dashboard.

@ktam3 ktam3 linked an issue Aug 28, 2024 that may be closed by this pull request
@RobotSail
Copy link
Member

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Aug 28, 2024

rebase

✅ Branch has been successfully rebased

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had activity within 90 days. It will be automatically closed if no further activity occurs within 30 days.

@github-actions github-actions bot added the stale label Dec 13, 2024
@booxter booxter force-pushed the cast-lora-modules-to-list branch from 596e6f0 to 0903867 Compare January 20, 2025 18:14
@booxter booxter marked this pull request as draft January 20, 2025 18:14
@RobotSail
Copy link
Member

not stale

@RobotSail RobotSail removed the stale label Jan 20, 2025
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had activity within 60 days. It will be automatically closed if no further activity occurs within 30 days.

@github-actions github-actions bot added the stale label Mar 22, 2025
@booxter booxter closed this Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Click converts lists into tuples when parsing args

4 participants